Alice Community  

Go Back   Alice Community > Alice 2 > Bugs and Troubleshooting

Reply
 
Thread Tools Display Modes
Bug in IEEERemainder function
Old
DickBaldwin
Guest
 
Status:
Posts: n/a
Default Bug in IEEERemainder function - 11-05-2007, 04:43 PM

If you call the IEEERemainder function to get the remainder of 7/2, the value returned is -1, which is incorrect.

If you call the IEEERemainder function to get the remainder of 8/3, the value returned is -1, which is incorrect.

If you call the IEEERemainder function to get the remainder of 5/2, the value returned is 1, which is correct.

Sometimes the function returns the correct answer and sometimes it returns the wrong answer. On the basis of a very limited amount of experimentation, it seems to return the correct answer for those cases where the correct answer is 0.

Dick Baldwin
Free Alice tutorials: http://www.dickbaldwin.com/tocalice.htm
Free programming tutorials: http://www.dickbaldwin.com/toc.htm

Last edited by DickBaldwin; 11-05-2007 at 04:44 PM. Reason: Clarification
   
Reply With Quote
Old
dragnet
Member
 
Status: Offline
Posts: 38
Join Date: Jan 2010
Default 03-23-2010, 12:07 AM

To those who care...and I do because I use modulo quite often. It seems that I had teh same problem as Dick. The IEEERemainder function does not seem to work the way I would expect with some combinations of numbers. If you are getting weird results back from IEEERemainder try creating this function:

modulo.jpg
   
Reply With Quote
IEEERemainder
Old
aikmin
Senior Member
 
aikmin's Avatar
 
Status: Offline
Posts: 85
Join Date: Mar 2008
Default IEEERemainder - 04-23-2010, 04:36 PM

Computes the remainder operation on two arguments as prescribed by the IEEE 754 standard. The remainder value is mathematically equal to f1 - f2 n, where n is the mathematical integer closest to the exact mathematical value of the quotient f1/f2, and if two mathematical integers are equally close to f1/f2, then n is the integer that is even. If the remainder is zero, its sign is the same as the sign of the first argument. Special cases:

If either argument is NaN, or the first argument is infinite, or the second argument is positive zero or negative zero, then the result is NaN.
If the first argument is finite and the second argument is infinite, then the result is the same as the first argument.
   
Reply With Quote
Old
flats
Guest
 
Status:
Posts: n/a
Default 04-24-2010, 09:11 AM

Short answer: There is no bug. IEEERemainder is working properly.

Long answer below:

Quote:
Originally Posted by aikmin View Post
Computes the remainder operation on two arguments as prescribed by the IEEE 754 standard. The remainder value is mathematically equal to f1 - f2 n, where n is the mathematical integer closest to the exact mathematical value of the quotient f1/f2, and if two mathematical integers are equally close to f1/f2, then n is the integer that is even. If the remainder is zero, its sign is the same as the sign of the first argument. Special cases:

If either argument is NaN, or the first argument is infinite, or the second argument is positive zero or negative zero, then the result is NaN.
If the first argument is finite and the second argument is infinite, then the result is the same as the first argument.
That is what the javadoc says. Let me try to clarify.

When you're taught a remainder in grade school, you're taught it's the bit leftover when you do division. 9 / 5 = 1 remainder 4, because 5 goes into 9 once, with 4 left over.

The IEEERemainder method works a little differently, and tries to make the absolute value of the remainder as small as possible. If you're doing 9/5, it finds the multiple of 5 closet to 9. In this case, 10 is closer to 9 than 5 is. But 10 is bigger than 9; it's 1 too big. So your remainder is negative 1.

Mathematically, your two cases are:

9 = 1 * 5 + 4
9 = 2 * 5 + -1

I was going to write you a method to turn IEEERemainder into the % operator, but since Dick already has an entire website of tutorials and should know his stuff, I guess I'll leave it as an exercise to the reader.

Last edited by flats; 04-24-2010 at 09:13 AM.
   
Reply With Quote
So
Old
arty-fishL
Senior Member
 
arty-fishL's Avatar
 
Status: Offline
Posts: 1,878
Join Date: Mar 2008
Location: In the corner of your eye
Question So - 04-26-2010, 02:30 PM

Is there a way to actually find the plain remainder of a number?


█░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░█
█░░▓░░░░░░░▓░░░░░░░░░░░▓▓░░▓░░░░░░▓░░░▓░░░░█
█░▓░▓░▓▓▓░▓▓▓░▓░▓░░░░░░▓▒▒░░▒░░▓▓░▓▓▓░▓▒░░░█
█░▓▓▓▒▓▒▒▒░▓▒▒▓▓▓▒▓▓▓░▓▓▓░░▓░░░▓▒▒▓▒▓▒▓▒░░░█
█░▓▒▓▒▓▒░░░▓▓░░▒▓▒░▒▒▒░▓▒▒░▓▓░▓▓▒░▓▒▓▒▓▒░░░█
█░▓▒▓▒░▒░░░░▒▒▓▓▓▒░░░░▓▓▒░░░▒▒░▒▒░░▒░▒▓▓▓░░█
█░░▒░▒░░░░░░░░░▒▒▒░░░░░▒▒░░░░░░░░░░░░░░▒▒▒░█
█░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░█

I have mostly moved on from Alice, but may still respond to messages if important [-]
   
Reply With Quote
Old
arty-fishL
Senior Member
 
arty-fishL's Avatar
 
Status: Offline
Posts: 1,878
Join Date: Mar 2008
Location: In the corner of your eye
Lightbulb 04-26-2010, 03:04 PM

Quote:
Originally Posted by arty-fishL View Post
Is there a way to actually find the plain remainder of a number?
Actually, I've found a way (this is a custom function):
Attached Images
File Type: jpg remainder finder.jpg (56.9 KB, 39 views)


█░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░█
█░░▓░░░░░░░▓░░░░░░░░░░░▓▓░░▓░░░░░░▓░░░▓░░░░█
█░▓░▓░▓▓▓░▓▓▓░▓░▓░░░░░░▓▒▒░░▒░░▓▓░▓▓▓░▓▒░░░█
█░▓▓▓▒▓▒▒▒░▓▒▒▓▓▓▒▓▓▓░▓▓▓░░▓░░░▓▒▒▓▒▓▒▓▒░░░█
█░▓▒▓▒▓▒░░░▓▓░░▒▓▒░▒▒▒░▓▒▒░▓▓░▓▓▒░▓▒▓▒▓▒░░░█
█░▓▒▓▒░▒░░░░▒▒▓▓▓▒░░░░▓▓▒░░░▒▒░▒▒░░▒░▒▓▓▓░░█
█░░▒░▒░░░░░░░░░▒▒▒░░░░░▒▒░░░░░░░░░░░░░░▒▒▒░█
█░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░█

I have mostly moved on from Alice, but may still respond to messages if important [-]
   
Reply With Quote
Old
flats
Guest
 
Status:
Posts: n/a
Default 04-27-2010, 02:48 PM

Quote:
Originally Posted by arty-fishL View Post
Is there a way to actually find the plain remainder of a number?
Code:
If (IEEERemainder (a,b) < 0)
     Return IEEERemainder (a,b) + b
Else
     Return IEEERemainder (a,b)
edit: Your method will work as well.

If you have a positive remainder function, to turn it to IEEERemainder:

Code:
If (remainder(a,b) > b/2)
     Return remainder(a,b) - b
Else
     Return remainder(a,b)

Last edited by flats; 04-27-2010 at 02:50 PM. Reason: I Triple E
   
Reply With Quote
;]
Old
arty-fishL
Senior Member
 
arty-fishL's Avatar
 
Status: Offline
Posts: 1,878
Join Date: Mar 2008
Location: In the corner of your eye
Thumbs up ;] - 04-27-2010, 03:05 PM

Quote:
Originally Posted by flats View Post
Code:
If (IEEERemainder (a,b) < 0)
     Return IEEERemainder (a,b) + b
Else
     Return IEEERemainder (a,b)
edit: Your method will work as well.
...
Your smart.


█░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░█
█░░▓░░░░░░░▓░░░░░░░░░░░▓▓░░▓░░░░░░▓░░░▓░░░░█
█░▓░▓░▓▓▓░▓▓▓░▓░▓░░░░░░▓▒▒░░▒░░▓▓░▓▓▓░▓▒░░░█
█░▓▓▓▒▓▒▒▒░▓▒▒▓▓▓▒▓▓▓░▓▓▓░░▓░░░▓▒▒▓▒▓▒▓▒░░░█
█░▓▒▓▒▓▒░░░▓▓░░▒▓▒░▒▒▒░▓▒▒░▓▓░▓▓▒░▓▒▓▒▓▒░░░█
█░▓▒▓▒░▒░░░░▒▒▓▓▓▒░░░░▓▓▒░░░▒▒░▒▒░░▒░▒▓▓▓░░█
█░░▒░▒░░░░░░░░░▒▒▒░░░░░▒▒░░░░░░░░░░░░░░▒▒▒░█
█░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░█

I have mostly moved on from Alice, but may still respond to messages if important [-]

Last edited by arty-fishL; 04-27-2010 at 03:06 PM. Reason: quote was too long
   
Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump



Copyright ©2019, Carnegie Mellon University
Alice 2.x 1999-2012, Alice 3.x 2008-2012, Carnegie Mellon University. All rights reserved.