Forums: Forum of Decimal BASIC (Thread #38459)

ROUND() Function Error in Compiler (2017-03-08 22:24 by TomL_12953 #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

Reply to #79522×

You can not use Wiki syntax
You are not logged in. To discriminate your posts from the rest, you need to pick a nickname. (The uniqueness of nickname is not reserved. It is possible that someone else could use the exactly same nickname. If you want assurance of your identity, you are recommended to login before posting.) Login

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

Your program gives me the result 1.0002!

I use Linux version 6.6.1.0 (x86_64)
Reply to #79522

Reply to #79529×

You can not use Wiki syntax
You are not logged in. To discriminate your posts from the rest, you need to pick a nickname. (The uniqueness of nickname is not reserved. It is possible that someone else could use the exactly same nickname. If you want assurance of your identity, you are recommended to login before posting.) Login

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

Your program gives me the result 1.0002!

I use Linux version 6.6.1.0 (x86_64)
Reply to #79522

Reply to #79530×

You can not use Wiki syntax
You are not logged in. To discriminate your posts from the rest, you need to pick a nickname. (The uniqueness of nickname is not reserved. It is possible that someone else could use the exactly same nickname. If you want assurance of your identity, you are recommended to login before posting.) Login

Re: ROUND() Function Error in Compiler (2017-03-10 03:00 by bspinoza #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
Reply to #79530

Reply to #79531×

You can not use Wiki syntax
You are not logged in. To discriminate your posts from the rest, you need to pick a nickname. (The uniqueness of nickname is not reserved. It is possible that someone else could use the exactly same nickname. If you want assurance of your identity, you are recommended to login before posting.) Login

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.

Tom L
Reply to #79531

Reply to #79533×

You can not use Wiki syntax
You are not logged in. To discriminate your posts from the rest, you need to pick a nickname. (The uniqueness of nickname is not reserved. It is possible that someone else could use the exactly same nickname. If you want assurance of your identity, you are recommended to login before posting.) Login

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.

Tom L
Reply to #79530

Reply to #79532×

You can not use Wiki syntax
You are not logged in. To discriminate your posts from the rest, you need to pick a nickname. (The uniqueness of nickname is not reserved. It is possible that someone else could use the exactly same nickname. If you want assurance of your identity, you are recommended to login before posting.) Login

Re: ROUND() Function Error in Compiler (2017-03-15 12:11 by SHIRAISHI Kazuo #79546)

BASICAcc operates on binary floating points.
1.002 in decimal is recurring fraction on binary numeric system.
Reply to #79532

Reply to #79546×

You can not use Wiki syntax
You are not logged in. To discriminate your posts from the rest, you need to pick a nickname. (The uniqueness of nickname is not reserved. It is possible that someone else could use the exactly same nickname. If you want assurance of your identity, you are recommended to login before posting.) Login

Re: ROUND() Function Error in Compiler (2017-03-15 19:57 by TomL_12953 #79548)

[Reply To Message #79546]
> BASICAcc operates on binary floating points.
> 1.002 in decimal is recurring fraction on binary numeric system.

So why does it work as expected in the Linux version?

Tom L
Reply to #79546

Reply to #79548×

You can not use Wiki syntax
You are not logged in. To discriminate your posts from the rest, you need to pick a nickname. (The uniqueness of nickname is not reserved. It is possible that someone else could use the exactly same nickname. If you want assurance of your identity, you are recommended to login before posting.) Login

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.


Reply to #79548

Reply to #79549×

You can not use Wiki syntax
You are not logged in. To discriminate your posts from the rest, you need to pick a nickname. (The uniqueness of nickname is not reserved. It is possible that someone else could use the exactly same nickname. If you want assurance of your identity, you are recommended to login before posting.) Login

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.

Reply to #79549

Reply to #79550×

You can not use Wiki syntax
You are not logged in. To discriminate your posts from the rest, you need to pick a nickname. (The uniqueness of nickname is not reserved. It is possible that someone else could use the exactly same nickname. If you want assurance of your identity, you are recommended to login before posting.) Login

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.
Reply to #79550

Reply to #79551×

You can not use Wiki syntax
You are not logged in. To discriminate your posts from the rest, you need to pick a nickname. (The uniqueness of nickname is not reserved. It is possible that someone else could use the exactly same nickname. If you want assurance of your identity, you are recommended to login before posting.) Login

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.

Tom L
Reply to #79551

Reply to #79563×

You can not use Wiki syntax
You are not logged in. To discriminate your posts from the rest, you need to pick a nickname. (The uniqueness of nickname is not reserved. It is possible that someone else could use the exactly same nickname. If you want assurance of your identity, you are recommended to login before posting.) Login