Re: float/double calculation bug ?

2017-03-19 Thread Søren Berg Glasius
Hi, This discussion does not belong on the dev mailing list, but the user mailing list (*us...@groovy.apache.org )*. Please continue your very interesting discussion there :-) Thanks. /Søren On Sun, 19 Mar 2017 at 16:47 James Bond wrote: What happens if you use .toDouble() instead of .toFloat,

Re: float/double calculation bug ?

2017-03-19 Thread Edmond Kemokai
Seems like floating point approximation at runtime. Interestingly enough your code works with exact result when I try it but any minor reformulation ends up with the approximate result. Also when I replace your computation with literal integers I get the exact result...floating point arithmetic can

Re: float/double calculation bug ?

2017-03-19 Thread James Bond
What happens if you use .toDouble() instead of .toFloat, and an explicitly double 100.0 literal? Right now, your computation is taking an integer, dividing by a float, then multiplying by another float. I suspect that going double precision won't fix this in all cases (floating point math is, aft

Re: float/double calculation bug ?

2017-03-19 Thread Derek Visch
Looks like floating point to me, what are you expecting? On Mar 19, 2017 10:04 AM, "Tx. T" wrote: > Any idea why the follow code "calc" returns the "70%" of the 33 > incorrectly? > > testing on: Groovy Version: 2.4.9 JVM: 1.8.0_112 Vendor: Oracle Corporation > OS: Mac OS X > > Mac OS X 10.

float/double calculation bug ?

2017-03-19 Thread Tx. T
Any idea why the follow code "calc" returns the "70%" of the 33 incorrectly?testing on: Groovy Version: 2.4.9 JVM: 1.8.0_112 Vendor: Oracle Corporation OS: Mac OS XMac OS X 10.12.3 groovy:000> def calc = { amount, ttl -> groovy:001> double rtn groovy:002> if (amount[-1] !