It is currently Wed Jun 28, 2017 3:43 pm



Welcome
Welcome to rfobasic

You are currently viewing our boards as a guest, which gives you limited access to view most discussions and access our other features. By joining our free community, you will have access to post topics, communicate privately with other members (PM), respond to polls, upload content, and access many other special features. In addition, registered members also see less advertisements. Registration is fast, simple, and absolutely free, so please, join our community today. **You are not required to provide truthful information to any registration questions. Be whomever you wish to be.!


Post new topic Reply to topic  [ 4 posts ] 
Author Message
 Post subject: FRAC() does not work correctly with big numbers like 4.5E8
Unread postPosted: Tue Apr 11, 2017 5:25 pm 
Offline
User avatar

Joined: Wed Jul 10, 2013 8:11 am
Posts: 364
New Github issue #234

t = time()
print t
print t/1000
print frac(t/1000)
? t/1000 - int(t/1000)

/ Gregor


Top
 Profile  
 
 Post subject: Re: FRAC() does not work correctly with big numbers like 4.5
Unread postPosted: Tue Apr 11, 2017 9:53 pm 
Offline
User avatar

Joined: Tue Jan 03, 2012 9:31 am
Posts: 5543
Location: Paris, France
Have you looked if it's not a Java issue? We can't fix Android Java limitations...

_________________
- Creator of the Android BASIC! Compiler


Top
 Profile  
 
 Post subject: Re: FRAC() does not work correctly with big numbers like 4.5
Unread postPosted: Thu Apr 13, 2017 2:05 am 
Offline
User avatar

Joined: Wed Jul 10, 2013 8:11 am
Posts: 364
The issue is the result of the java function .toString().


Top
 Profile  
 
 Post subject: Re: FRAC() does not work correctly with big numbers like 4.5
Unread postPosted: Tue Jun 13, 2017 4:36 pm 
Offline

Joined: Wed Oct 03, 2012 9:53 am
Posts: 2802
Location: Colorado, U.S.
(Two months later!)
Gregor is right. We have discussed this quite a bit on GitHub.

BASIC! numbers are Java double-precision floating point. They have 52 bits of precision. Converted to decimal, that's described as "15.9 decimal digits". What does that even mean???

Well, it means that just a few BASIC! numbers are accurate to 17 digits, almost all are accurate to 16, and just a few are accurate only to the 15th digit. Because there's no easy way to tell which ones are accurate to how many digits, you have to assume any digits past 15 are WRONG.

The BASIC! PRINT statement uses Java .toString(), as Gregor said, which prints 17 significant digits. I really, truly wish that either
1. It didn't do that, OR
2. BASIC! only printed 15 digits, correctly rounded.

So my fix for FRAC() is going to be to round to 15 digits.

Furthermore, I am seriously considering changing BASIC! so everything always rounds to 15 digits. It would be a very small performance hit (internally, everything is binary, it would only round when converting to decimal, that is, when you PRINT). I just can't decide whether this counts as backward-compatible or not.

- Marc


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 4 posts ] 


Who is online

Users browsing this forum: No registered users and 0 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
cron
suspicion-preferred