Re: ROUND() Function Error in Compiler (2017-03-10 02:48 by bspinoza #79529)
[Reply To Message #79522]
> In the following code, BASIC should print 1.0002. Instead it prints
>
> 1.00019999999999
>
> LET T=1.00015000999908
> PRINT round(T,4)
> END
>
> Tom Lake
Re: ROUND() Function Error in Compiler (2017-03-10 02:48 by bspinoza #79530)
[Reply To Message #79522]
> In the following code, BASIC should print 1.0002. Instead it prints
>
> 1.00019999999999
>
> LET T=1.00015000999908
> PRINT round(T,4)
> END
>
> Tom Lake
Re: ROUND() Function Error in Compiler (2017-03-10 04:34 by TomL_12953 #79533)
[Reply To Message #79531]
> [Reply To Message #79530]
>
> And what about the following code (my result is also 1.0002)?
>
> LET a = 1.00015000999908
> LET n = 4 !number of decimal places
> LET ROUND = INT(a*10^n+0.5)/10^n
> PRINT ROUND
> END
I still get 1.00019999999999 with the above program.
Re: ROUND() Function Error in Compiler (2017-03-10 04:30 by TomL_12953 #79532)
[Reply To Message #79530]
> [Reply To Message #79522]
> > In the following code, BASIC should print 1.0002. Instead it prints
> >
> > 1.00019999999999
> >
> > LET T=1.00015000999908
> > PRINT round(T,4)
> > END
> >
> > Tom Lake
>
> Your program gives me the result 1.0002!
>
> I use Linux version 6.6.1.0 (x86_64)
Hmm. I'm using BASIC Accelerator 1.0 with 64-bit Lazarus 1.64 fpc 3.0.2 on 64-bit Windows 10.
Re: ROUND() Function Error in Compiler (2017-03-15 21:12 by SHIRAISHI Kazuo #79549)
OPTION ARITHMETIC NATIVE
LET T=1.00015000999908
PRINT round(T,4)
PRINT USING "#.###################":ROUND(T,4)
END
On Decimal BASIC, results are
1.0002
1.0001999999999999770
And on BASICAcc 32bit operation, results are
1.0002
1.0001999999999999000
These mean PRINT Statements display rounded values.
Other system uses other rounding routine.
Windows 64 bit version of BASICAcc can not use 80 bit floating point operation. So, on BASICAcc 64bit operation, rounding on display is far from that of 32 bit operation.
Re: ROUND() Function Error in Compiler (2017-03-15 21:37 by SHIRAISHI Kazuo #79550)
On 64 bit Linux, results are
1.0002
1.0001999999999999000
,which coincide with results of BASICAcc 32 bit operation on Windows.
Because Linux 64 bit allows use of 80 bit operation, the rounding system is equivalent to that of 32 bit mode for BASICAcc.
Re: ROUND() Function Error in Compiler (2017-03-16 08:55 by SHIRAISHI Kazuo #79551)
On 64 bit operation on Windows, results are
1.00019999999999
1.0001999999999900000
These are consequences of making display numeral routine having insuffient digits.
this is only a problem on displaying numerals, not a problem on numerical operation.
But, on Windows, 64 bit mode occasionally works inaccurate.
If both speed and accuracy needed, working on 64 bit Linux is recommended.
If the PC has sufficient memory, 64 bit Linux can run in VirtualBox or VMware.
Re: ROUND() Function Error in Compiler (2017-03-20 21:08 by TomL_12953 #79563)
[Reply To Message #79551]
> On 64 bit operation on Windows, results are
>
> 1.00019999999999
> 1.0001999999999900000
>
> These are consequences of making display numeral routine having insuffient digits.
> this is only a problem on displaying numerals, not a problem on numerical operation.
> But, on Windows, 64 bit mode occasionally works inaccurate.
> If both speed and accuracy needed, working on 64 bit Linux is recommended.
> If the PC has sufficient memory, 64 bit Linux can run in VirtualBox or VMware.
Thank you for your detailed explanation. I really appreciate all the work you put into Decimal BASIC with no thought of profit.