Wrox Home  
Search P2P Archive for: Go

  Return to Index  

javascript thread: RE: Modulus is sending me crazy!!


Message #1 by Greg Hill <ghill@s...> on Fri, 30 Nov 2001 18:48:01 -0800
Microsoft wrote that BTW.
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/script56/ht
ml/js56jsoprmod.asp


Cory


-----Original Message-----
From: Greg Hill [mailto:ghill@s...]
Sent: Friday, November 30, 2001 6:48 PM
To: javascript
Subject: [javascript] RE: Modulus is sending me crazy!!


Cory,

Perhaps you would be so kind as to do us all a favor by notifying
whoever is responsible for maintaining that documentation of the
erratum.

Thanks for your help.

--Greg



===========================================================================
>This same code gives me 5.6 as well, even though the Jscript documentation
>says it will be 5.
>
>
>MicrosoftR JScriptR
>% Operator   Language Reference
>Version 1
>---------------------------------------------------------------------------
-
>----
>Description
>Divides two numbers and returns the remainder.
>Syntax
>result = number1 % number2
>The % operator syntax has these parts:
>
>Part Description
>result Any variable.
>number1 Any numeric expression.
>number2 Any numeric expression.
>
>
>Remarks
>The modulus, or remainder, operator divides number1 by number2 (rounding
>floating-point numbers to integers) and returns only the remainder as
>result. For example, in the following expression, A (which is result)
equals
>5.
>A = 19 % 6.7
>
>For information on when a run-time error is generated by the % operator,
see
>the Operator Behavior table.
>
>
>
>
>
>
>
>-----Original Message-----
>From: Greg Hill [mailto:ghill@s...]
>Sent: Friday, November 30, 2001 3:01 PM
>To: javascript
>Subject: [javascript] RE: Modulus is sending me crazy!!
>
>Mark, Matt,
>
>When I execute
>
>         document.write("19 % 6.7 = " + (19 % 6.7) + "<br>")
>
>I get
>
>         19 % 6.7 = 5.6
>
>which is exactly what I expected.  I would be curious to see the code that
>either of you is executing to get a result of 5.0.
>
>Mark,
>
>The reason that 19 % 6.7 = 5.6 is that
>
>         19 - 6.7 - 6.7 = 5.6
>--Greg
>
>
>6.7 gets coerced to the integer greater than or equal to 6.7, so the
>expression gets interpreted as 19 % 7 (which equals 5).
>
>-----Original Message-----
>From: Mark Irvine [mailto:mark@m...]
>Sent: Friday, November 30, 2001 4:59 PM
>To: javascript
>Subject: [javascript] Modulus is sending me crazy!!
>
>
>
>Hi,
>
>I have having a really difficult time grasping the concept of the modulus
>(%) function.  I am aware that the function returns only the remainder of
>the sum and that it converts floats to integer before division, however I
>cannot understand how 19 % 6.7 = 5.
>
>I hope somebody will be able to explain this for me?
>
>Many thanx,
>
>Mark


Read the future with ebooks at B&N
http://service.bfast.com/bfast/click?bfmid=2181&sourceid=38934667&categoryid
=rn_ebooks


  Return to Index