It is currently Tue May 23, 2017 9:49 am



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: Decimal Math
Unread postPosted: Wed Apr 26, 2017 3:06 pm 
Offline

Joined: Sat Dec 26, 2015 8:37 pm
Posts: 30
All numbers are in floating point format which causes problems when dealing with amounts like currency. The manual states "Mathematical operations on decimal values are imprecise." Multiplying and dividing by 100 seems to be a work-around but is not exactly elegant. Also, I am not sure that it will always guarantee accuracy.

An enhancement would be to have another data type for numbers. There are many other languages that support true decimal numbers (often in packed BCD format) to solve this problem. I realize that supporting a new data type is not simple, and it involves all new math functions. I would be happy to help out with this project but I need some guidance since I have never written anything in Java. I have been thinking about writing a Decimal package in basic using strings to hold the numbers.

Any thoughts?

Robert


Report this post
Top
 Profile  
 
 Post subject: Re: Decimal Math
Unread postPosted: Thu Apr 27, 2017 1:38 am 
Offline

Joined: Tue Dec 04, 2012 10:50 am
Posts: 656
Location: UK
The "imprecision" is going to be adequate for currency unless you are dealing with multi-billion amounts!

Mike.


Report this post
Top
 Profile  
 
 Post subject: Re: Decimal Math
Unread postPosted: Thu Apr 27, 2017 12:38 pm 
Offline
User avatar

Joined: Thu Nov 21, 2013 7:00 pm
Posts: 638
mjcoon wrote:
The "imprecision" is going to be adequate for currency unless you are dealing with multi-billion amounts!

Mike.

..Or really small numbers with lots of decimal places!
(BTW, a billion is worth a lot in some currencies, but not so much in others.)

The precision will matter if you are furthur amplifying the result to things like money.

Java has a BigDecimal class, and I think rrioja is right, it'll be (too Big a) job to integrate into Basic! :)
Probably easier to write your own library.

You can still get accurate results with floating point alone and proper rounding (see ROUND). Decimal arithmetic just makes it clearer.

_________________
- Failure is not an option. It is bundled with the software. -


Report this post
Top
 Profile  
 
 Post subject: Re: Decimal Math
Unread postPosted: Fri May 12, 2017 5:14 am 
Offline
User avatar

Joined: Wed Jul 10, 2013 8:11 am
Posts: 325
Hi Robert,

At
hot-summer-of-code-t4408-80.html
you find the newest test version with description etc.
and BigDecimal support. :)

Happy coding
Gregor


Report this post
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 2 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:  
suspicion-preferred