This week's book giveaway is in the OCAJP 8 forum.We're giving away four copies of OCA Java SE 8 Programmer I Study Guide and have Edward Finegan & Robert Liguori on-line!See this thread for details.
Big Moose Saloon
 Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies Register / Login Win a copy of OCA Java SE 8 Programmer I Study Guide this week in the OCAJP 8 forum!

# IEEremainder

Anuji Philip
Ranch Hand

Joined: Feb 25, 2002
Posts: 46
In java.lang.Math package ,function IEEEremainder(double,double)
produces output differently,
IEEEremainder(2,4) = 2
IEEEremainder(2.0,5.0) = 2
IEEEremainder(2,5) =1
I thought I will get remainder zero
Ranch Hand

Joined: Jan 18, 2002
Posts: 178
I got, Math.IEEEremainder(2, 5) == 2.0

<a href="http://www.rajindery.com" target="_blank" rel="nofollow">Rajinder Yadav</a><p>Each problem that I solved became a rule which served afterwards to solve other problems. --Rene Descartes
Seany Iris
Ranch Hand

Joined: Jan 08, 2002
Posts: 54
I am very confused:
Math.IEEEremainder(3,5)==-2.0,while Math.IEEEremainder(2,5)==2.0
who can explain it to me?

Valentin Crettaz
Gold Digger
Sheriff

Joined: Aug 26, 2001
Posts: 7610
Ok first off, the correct values are:
Math.IEEEremainder(2,4) = 2.0
Math.IEEEremainder(2.0,5.0) = 2.0
Math.IEEEremainder(2,5) = 2.0
Math.IEEEremainder(3,5) = -2.0
So please verify your outputs before posting, so that people won't have to wonder why the hell an answer is wrong. Thanks!
Moreover,I think the api doc makes it clear...

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.

Math.IEEEremainder(2,4) = 2.0
2/4 is 0.5 and the closest integers are 0 and 1, we take the closest even one which is 0, so (double)2-4*0 = 2.0
Math.IEEEremainder(2.0,5.0) = 2.0
2.0/5.0 is 0.4 so the closest integer is 0, so (double)2.0-5.0*0 = 2.0
Math.IEEEremainder(2,5) = 2.0
2/5 is 0.4 so the closest integer is 0, so (double)2-5*0 is 2.0
Math.IEEEremainder(3,5) = 2.0
3/5 is 0.6 so the closest integer is 1, so (double)3-5*1 = -2.0
I don't see any weird results...
[ February 27, 2002: Message edited by: Valentin Crettaz ]

SCJP 5, SCJD, SCBCD, SCWCD, SCDJWS, IBM XML
[Blog] [Blogroll] [My Reviews] My Linked In
Seany Iris
Ranch Hand

Joined: Jan 08, 2002
Posts: 54
Great!I got it.
thank you val!

I agree. Here's the link: http://aspose.com/file-tools

subject: IEEremainder