Alaska Software Inc. - Once Again Major BUG with Sums, Int() and Round()
Username: Password:
AuthorTopic: Once Again Major BUG with Sums, Int() and Round()
Paulo PinheiroOnce Again Major BUG with Sums, Int() and Round()
on Tue, 19 Jan 2010 13:31:54 +0000
Hello All and specialy Alaska....

Major BUG!!!!

x := 6.17
?x          => 6.17

x := x - Int( x )
?x        ==> 0.17

x := x*100
?x        ==> 17.00

x := Int( x )
?x        =============> 16 !!!!!!!!!!


I have to do Int( Round( x, 2 ) ) so it gives 17 !!!!!



When will this be over?????
Alaska should do a BIG EFFORT to solve this once and for all.....


I am realy sorry for this not so friendly post but it is very frustrating to 
be back at this problem.
This bug is not always catched at first and in development time.....
Sometimes is a very HUNGRY client that reports the BUG!!!!

Best regards,
Paulo Pinheiro
Thomas Braun
Re: Once Again Major BUG with Sums, Int() and Round()
on Tue, 19 Jan 2010 16:03:28 +0100
Paulo Pinheiro wrote:

> Hello All and specialy Alaska....
> 
> Major BUG!!!!

Unfortunately, this is no bug... please read on 

> 
[sample snipped]
> 
> I have to do Int( Round( x, 2 ) ) so it gives 17 !!!!!

Rounding is exactly what you have to do to get correct results.

> When will this be over?????

It won't be over ever - at least not with the way numbers are represented
in most computer languages.

It is a fact that the infinite amount of real numbers can't be accurately
represented in a finite amount of bits.

In this case, "17" might be represented as "16.99999999999999" internally,
so using INT() you simply cut off the decimals, leaving you with an
innocent "16" 

For more details please refer to:

http://en.wikipedia.org/wiki/Floating_point#Accuracy_problems

There are number representations, namely BCD, that avoid these problems -
but this requires a set of specialized routines for carrying out
calculations that are more complex than with a pure binary representation. 

Please see 

http://en.wikipedia.org/wiki/Binary-coded_decimal#Comparison_with_pure_binary

for more details.

regards
Thomas
Thomas Braun
Re: Once Again Major BUG with Sums, Int() and Round()
on Tue, 19 Jan 2010 16:07:31 +0100
Hi Paulo,

one small additional comment/though from my side...

This discussion pops up every now and then, but I don't think I can
remember having seen any official statement from the Alaska team about this
at all.

So most likely everything has already been said in those discussions and
there is not much what Alaska can do about this...

Thomas
Thomas Braun
Re: Once Again Major BUG with Sums, Int() and Round()
on Tue, 19 Jan 2010 16:14:00 +0100
Addendum 2:

please also try the following code to see 17 != 17:

   SET DECIMALS TO 12
   SET FIXED ON

   x := 6.17
   x := x - Int( x )
   x := x*100
   ?X*10000000000000
   ?(x-17) * 100000000000

regards
Thomas