Navigate
Home
ArticleWiki
Forum
Journal
Search
Newsletter
Links
Tech News
expertsrt.com
Welcome Guest.
Username:

Password:

Remember me

Modulous and what Remains
Welcome, Guest. Please login or register.
December 03, 2008, 11:39:07 PM
11306 Posts in 1249 Topics by 499 Members
Latest Member: haulaslemycle
Experts Round Table Network  |  Serverside Technology  |  PHP  |  Modulous and what Remains « previous next »
Pages: [1]
Author Topic: Modulous and what Remains  (Read 385 times)
fedoracore

Offline Offline

Posts: 35



« on: January 30, 2007, 12:04:32 AM »

hi.

the Modulous operator is one which i've always found to be a bit tricky.

i'm curious about a bit of code from a calendar application, wherein a for loop takes date info and creates an HTML table-- using just enough rows for the output so it looks nice.

here is the bit of code. i can't seem to get my head around it. if someone has an extra moment, i'd love to read the commentary of a more experienced programmer as to-- essentailly "what's going on here" -- in particular, the if($count) modulous seven bit (3rd line down):

 for ($count=0$count < (6*7); $count++) {
     
$dayArray getdate($start);
     if ((
$count 7) == 0) {
          if (
$dayArray['mon'] != $month) {
            break;
         } else {
            echo 
"</tr><tr>\n";
         }
   }
   if (
$count $firstDayArray['wday'] || $dayArray['mon'] != $month) {
       echo 
"<td>&nbsp;</td>\n";
   } else {
       echo 
"<td>".$dayArray['mday']." &nbsp;&nbsp; </td>\n";
        
$start += ADAY;
   }
}

// Excerpt from Ch22, Sample apps in the very awesome quick-start book:
// Sams Teach Yourself PHP, MySQL® and Apache All in OneBy Julie C. Meloni : Sams Publishing : December 18, 2003

EDIT: let me rephrase my question. it would probably be better for me to ask:
Does anyone have another good example of the use of the '%' operator?

i'm thinking of trying to convert this "app" into a more robust thing, maybe put it as a Method of a Class-- and make a bonafide "calendar" data entry thing from it. but it's this part where i'm a little sketchy. would it be safe to say that the Modulous is being used only to separate the HTML table cells? it is not really part of the date calcs, right?

thanks. sorry i don't konw how to ask a question. it's really more seeking rhetorical reply than anything, so i'll accept it if no one has time to provide input here. :wink:
« Last Edit: January 30, 2007, 12:12:44 AM by fedoracore » Logged

"...In search of my inner Joomla"
GrandSchtroumpf
Mentor

Offline Offline

Posts: 411



« Reply #1 on: January 30, 2007, 04:56:50 AM »

> would it be safe to say that the Modulous is being used only to separate the HTML table cells?
yes, that's correct.  it's only used to create a new row for a new week.
(($count % 7) == 0) is true only when $count is a multiple of 7.
Logged
COBOLdinosaur
ERT.com Admin

Offline Offline

Posts: 481



WWW
« Reply #2 on: January 30, 2007, 07:30:43 AM »

Here is a common use for the mod operator. 

If you are generating a table and it is groups of three lines: current year totals, previous year totals and the difference. You want to have the difference rows (every third row) to be a different color. So you create a couple of CSS classes and apply them to the rows.  All you need is a way to determine when you are on the third row of each set:


$rowclass='normalclass';
for (i=1;i<=$totalrows;i++)
{
   $rowclass=($rowcount^3==0) ? 'diffclass' : 'normalclass';
   print '<tr class="' . $rowclass .'">';
   //more prints statements for the cells
   print '</tr>';
}

For the common presentation of alternating row colors you use 2 instead of 3 for the mod operator.

Mod can be used to give you an interupt mechanism where every you need to do special processing based on intermediate breakpoints.  The result will always be zero only for the exact value you want to break on.
 
 Cd&
Logged
fedoracore

Offline Offline

Posts: 35



« Reply #3 on: January 30, 2007, 08:59:20 AM »

hey there fellas. thanks to the both of you!!

@GrandSchtroumpf
..(($count % 7) == 0) is true only when $count is a multiple of 7...
thank you, GS, for telling me what i was trying to ask. ;)
yes, this is precisely what i had in mind when i came here to ask about it
maybe some day we'll have web-cam-enabled, real-time forums-- in which it would make sense to say: "..but, what does this part mean?", but until then... hehe

this is VERY good info, COBOL-man. ;)
that's awesome about the CSS thing. haha-- i was trying to do that once (i think to decorate a PHPbb2) , and no one in this CSS forum could tell me what to do w/ it-- it was "settled" to use some sort of Rule of Cascade to get it to work-- which surprisingly, i think it did an okay job-
this of course, is much more accurate, and-- for me-- the preferred way to do it. though i dig CSS, sometimes... oftentimes i get a little frustrated w/ "WHY!" isnt'  this working!!... too many things to go wrong... whereas the mathematical precision-- there's no guesswork. nice and clean. also, this is a prespective on "dynamic CSS" which i've overlooked. i've been trying to do, for example: stylesheet.css.php
header('text/css');
..sort of thing... but i haven't gotten very far w/ it.

thanks again, gentlemen!!!
this, i will carry with me.
Logged

"...In search of my inner Joomla"
VGR
Mentor

Offline Offline

Posts: 682



WWW
« Reply #4 on: January 30, 2007, 11:57:04 AM »

some caveats :

using MODulo (% operator, in here) can be tricky depending if you count your data index from zero or from 1
using MOD only is also tricky when it comes to pagination and to treat the special cases (when there is a rest, mathematically speaking)

I think I have working code, so if you're interested let me know
Logged

techie overlord, answers all kind of questions on http://www.europeanexperts.org
rdivilbiss
Governing Council Member
*
Offline Offline

Posts: 414



WWW
« Reply #5 on: January 30, 2007, 12:27:12 PM »

Thanks to K.F.Gauss (1777-1855).

Just another way to think about this: Remember long division (before calculators) we wrote as follows: you could carry the division out past the decimal point, sometimes forever or until you had no remainder left, or sometimes you would only divide the whole number and write R # for remainder # (where # in an integer < the divisor). 



FWIW
Logged

Rod
VGR
Mentor

Offline Offline

Posts: 682



WWW
« Reply #6 on: January 30, 2007, 01:49:06 PM »

what a very strange way to draw a division operation ! :D
I doubt Gauss ever used that notation ;-)

Is this nottion the one taught in the U.S.A. ? Howdy strangy :D

I'm mathematician by formation, and I tought Maths were "the" universal language on Earth ;-)

I'm very disappointed (no kidding)

This is notation used anywhere in Europe (including Gauss's country) :
http://villemin.gerard.free.fr/Calcul/Operatio/DivInit.htm#gene
Logged

techie overlord, answers all kind of questions on http://www.europeanexperts.org
COBOLdinosaur
ERT.com Admin

Offline Offline

Posts: 481



WWW
« Reply #7 on: January 30, 2007, 02:53:55 PM »

That notation that Rod used is how it is taught in Canadian schools as well... or at least it was when I learned it in the 3rd grade many decades ago.  I guess we need to hear from other places in the ERT empire to see if there is a geographical or cultural basis for the differnce.  It would certainly not be the only difference. consider the decimal point 10,67 as opposed to 10.67

Logged
rdivilbiss
Governing Council Member
*
Offline Offline

Posts: 414



WWW
« Reply #8 on: January 30, 2007, 03:11:13 PM »

what a very strange way to draw a division operation ! :D
I doubt Gauss ever used that notation ;-)

Is this nottion the one taught in the U.S.A. ?

Yes that's what they use here.

http://www.youtube.com/watch?v=Tr1qee-bTZI

Here is my wife's Vietnamese version, which does not surprise me that it is similar to the French example considering the history.  Also she uses commas rather than decimal points. Her ones look like inverted Vs and her sevens are slashed.

« Last Edit: January 30, 2007, 03:13:58 PM by rdivilbiss » Logged

Rod
VGR
Mentor

Offline Offline

Posts: 682



WWW
« Reply #9 on: January 31, 2007, 12:10:36 AM »

Well, the 7 is supposed to be slashed... at least in the sanskrit/hindu/phoenician/arabic/western transmission ;-)

http://www.orthohelp.com/number.htm
Logged

techie overlord, answers all kind of questions on http://www.europeanexperts.org
rdivilbiss
Governing Council Member
*
Offline Offline

Posts: 414



WWW
« Reply #10 on: January 31, 2007, 09:47:24 AM »

Interesting.
Logged

Rod
fedoracore

Offline Offline

Posts: 35



« Reply #11 on: February 07, 2007, 08:48:59 PM »

@all
re: http://www.orthohelp.com/number.htm

is that "historical fact" right there, w/ the little "how many angles" thing, or is that some mneumonics thing someone learned in 4th grade or-- some "show me how to.." childhood riddle?
(i don't doubt it's historical-- but it reminds me of something like a riddle or some such "voodoo trickery")

but-- yeah, the Canadian / US American division is totally familiar to me-- and yet, i am not surprised that it elicits a scoff... as it would seem we (as i am from U.S.A.), we tend to do some stuff in all the whole long way around it. who knows why.

but i do like the slash in the seven. i do that-- but i thought it was to differentiate for my "chicken-scratch" so it doesn't look like a 2, or a 1  (i often write a 1 like the "serif" one, versus the sans-serif one)... esp. in "gvt documents". why? i dunno...

;)

oh-- and thanks, by the way!!! :)
Logged

"...In search of my inner Joomla"
rdivilbiss
Governing Council Member
*
Offline Offline

Posts: 414



WWW
« Reply #12 on: February 07, 2007, 09:22:25 PM »

Couldn't let the different notations go, so I contacted my Chinese grocerer (Mr. Ho.) mainland China, and he reports the US/Canadian notation.

I wonder if that is a British influence?  We've got a few brits about, so maybe someone will chime in.

Logged

Rod
VGR
Mentor

Offline Offline

Posts: 682



WWW
« Reply #13 on: February 07, 2007, 11:06:44 PM »

"English please" (sic!) as someone pointed out to me recently on this site

Use plain international-noslang-Oxfordian-English

no joking : think you have a more international audience than "the american site for Americans" (re-sic!)

You're lucky that RPGs made me know the noun "chime" ("clochette" pour ceux qui me lisent, voire "sonnerie" ou "sonnette"), but I confess that I don't understand "scoff", and the meaning of "chicken-scratch"

You don't want people to open a dictionary to surf the site, do you ? ;-))

Thank you
Logged

techie overlord, answers all kind of questions on http://www.europeanexperts.org
VGR
Mentor

Offline Offline

Posts: 682



WWW
« Reply #14 on: February 07, 2007, 11:53:42 PM »

now trying to "get historical" :

35 000 to 20 000 before J.-C. : Apparition des premiers os entaillés de la Préhistoire. (carved bones, one carf per unit)

5000 before J.-C. : Les Sumériens développent une numération parlée de base 60. (sexagesimal numbering) on stones - still used in China - and later on tablets

3300 to 3200 before  J.-C. : Apparition des chiffres sumériens et proto-élamites, tous deux considérés comme les plus anciens systèmes de numération connus. (first numberings in Elam and Sumer)

3000 to 2900 before J.-C. : Apparition de la numération hyéroglyphique égyptienne.
Example around -3500 :
and on papyrus or tablets :
Note the unit symbol

2700 before J.-C. : Apparition des chiffres cunéiformes sumériens

1900 to 1600 before J.-C. : Les Babyloniens développent le premier système de numération de position connu à ce jour. Utilisant la base 60, ce système ne comporte pas encore de zéro. (Babylone, sexagesimal base)

End of XIVe c. before J.-C. : Apparition des plus anciens chiffres chinois connus. (Chinese)

IIIe c. before J.-C. : Invention du zéro par les Babyloniens. Par contre, le zéro babylonien n'est pas conçu comme un nombre pouvant être utilisé lors de calculs. Il sert simplement à exprimer l'absence d'unités d'un certain ordre.

IIIe c. before  J.-C. : Apparition des chiffres brahmi (indiens). Les chiffres de ce système sont considérés comme les précurseurs des neuf chiffres de notre système de numération moderne.

original sanskrit (IV century)/hindu/ghubâr (occidental Arabs V-VII Century) versions :
note that the Arabs kept the Hindu way of writing chiffres (left-to-right) despite their right-to-left writing.
one version of north of Spain :
X Century :
In 913, the French monk Gerbert d'Aurillac tried to make Europe (ie, England and Northern Europe ;-) adopt the new way of writing down numbers ; it's only end of XIV th Century that this happened.
Around 1000, Pope Sylvestre II pushed very hard to mae the new notation adopted, but encountered opposition as Roman numbering (I, V, X, L, C, M etc) and Greek numbers were seen as a foundation of the civilisation.
Astrology treaty XIV C. (note the 7 not fixed) :
first printed characters (1473) note the 5 and 7 are the only ones remaining unset :
1700+ : invention of Romain(Roman), Garamond and Fournier typographical fonts :
from http://lechiffre.free.fr/chapter1/B-Naissance/titre1.html

from some teachers of my previous university :
in http://histoiredechiffres.neuf.fr/Firefox/histoiredechiffres.htm

About the meaning of "chiffre" (cypher) :

Sunya means empty (void) in Sanscrit, the zero is represented by a small circle (why? we don't know). Translated in Arabic, sunya becomes Sifr (the void).

"cifre" (Fr.) became "chifre" and finally "chiffre" and meant "the void"

About "zero" : The zero entered Occident in the 12th century ; translated in Italian sifr gave zéfirum, word that Léonard de Pise (ca 1170 - 1250) uses in his liber abaci and that will be used until the 15th century.After some modifications, the word ended in zéfiro, itself becoming zéro starting in 1491.

It's only in 1491 that "chiffre" meant "any representation in a numerical notation" and no longer "the void" (zero took that meaning)

So now about the "dash" in the 7 my answer is : "I don't know but it helps differentiate with the one" ;-)
Logged

techie overlord, answers all kind of questions on http://www.europeanexperts.org
Pages: [1]
« previous next »
    Jump to: