Theiling Online    Sitemap    Conlang Mailing List HQ   

Re: Programming a calendar system

From:Joe <joe@...>
Date:Wednesday, April 28, 2004, 16:02
Mark J. Reed wrote:

>On Wed, Apr 28, 2004 at 02:06:51PM +0200, Carsten Becker wrote: > > >>What are the normal division and the modulo division good for? And what >>would I have to write when 72 seconds ($asec) are 1 minute ($amin)? >> >> > >Modulo gives you the remainder after the division, which is therefore >the number of the next unit down. > >For instance, if I told you that 3,296 seconds had passed and asked you >what that was in minutes and seconds, then you would divide by 60; >the quotient is the number of minutes and the remainder is the number of >seconds into the next minute. > > 3296 / 60 = 54 > 3296 % 60 = 56 > >so 3,296 seconds is 54 minutes and 56 seconds, or 4 seconds shy of >55 minutes. > >Exactly how you compute this depends on the language. In many C-like >languages the type of the result of the '/' operator depends on the type >of its operands, so 3296 / 60 = 54, but 3296.0 / 60.0 = 56.933333333 >etc. In others the result of / is a float whenever the quotient is not >exact, and you have to explicitly apply a function (usually "floor") >to get integer form. > >
Though not, of course, in C itself, which simply gives the answer as an integer sans remainder.

Reply

<jcowan@...>