6502.org Forum  Projects  Code  Documents  Tools  Forum
It is currently Sun Oct 06, 2024 4:35 am

All times are UTC




Post new topic Reply to topic  [ 14 posts ] 
Author Message
PostPosted: Thu Dec 14, 2017 6:02 pm 
Offline
User avatar

Joined: Thu May 28, 2009 9:46 pm
Posts: 8414
Location: Midwestern USA
I was casting about for 10mm high intensity LEDs and found a site that sells them (said LEDs are no longer stock items with many electronics vendors). So I added them to my shopping cart. See below screen capture. Looks as though the site's math routines need a little rounding feature added. :D

Attachment:
File comment: Shopping Cart Rounding Error
rounding_error.gif
rounding_error.gif [ 12.52 KiB | Viewed 3736 times ]

_________________
x86?  We ain't got no x86.  We don't NEED no stinking x86!


Top
 Profile  
Reply with quote  
PostPosted: Fri Dec 15, 2017 1:11 pm 
Offline
User avatar

Joined: Wed Aug 17, 2005 12:07 am
Posts: 1228
Location: Soddy-Daisy, TN USA
Actually, it could be the same scheme used in Superman 3. That fraction of a penny is being routed to some evil mastermind's bank account.

_________________
Cat; the other white meat.


Top
 Profile  
Reply with quote  
PostPosted: Fri Dec 15, 2017 2:55 pm 
Offline

Joined: Wed Jan 08, 2014 3:31 pm
Posts: 578
Too funny.

Base-2 floating point numbers are pretty terrible for decimal financial calculations. After your computation you usually have some fiddly oddball number like 234.99999995 due to truncation errors. While approximately correct it needs to be massaged to eliminate errors. So you add back machine epsilon (e.g. 2^−24) and truncate at the last digit to eliminate those fiddly odd ball digits. So truncate(234.99999995 + 2^−24) would yield 235.0000000.

I seem to recall some programming languages having builtin functions to handle this in a machine independent manner.


Top
 Profile  
Reply with quote  
PostPosted: Fri Dec 15, 2017 2:57 pm 
Offline
User avatar

Joined: Tue Mar 05, 2013 4:31 am
Posts: 1383
Can you write them a check for payment?? :mrgreen:

_________________
Regards, KM
https://github.com/floobydust


Top
 Profile  
Reply with quote  
PostPosted: Fri Dec 15, 2017 4:54 pm 
Offline
User avatar

Joined: Thu Dec 11, 2008 1:28 pm
Posts: 10949
Location: England
Best way to round off to an integer is to add 0.5 and then truncate - no need to fiddle with very small numbers, or guess at the error.

To round to the nearest cent, multiply by 100 and then round off as above. Then shift the point by two places - don't divide!

As for the odd bill, best to overpay, or you'd be in debt for a fraction of a cent and might be pursued to the ends of the earth.


Top
 Profile  
Reply with quote  
PostPosted: Fri Dec 15, 2017 5:34 pm 
Offline

Joined: Wed Jan 08, 2014 3:31 pm
Posts: 578
BigEd wrote:
To round to the nearest cent, multiply by 100 and then round off as above. Then shift the point by two places - don't divide!

In finance they often keep track of interest rates in basis points which requires four digits of precision, plus a fifth digit to account for truncation errors. Various other financial instruments are also quoted with four decimal places of precision as well.


Top
 Profile  
Reply with quote  
PostPosted: Fri Dec 15, 2017 5:39 pm 
Offline
User avatar

Joined: Thu Dec 11, 2008 1:28 pm
Posts: 10949
Location: England
It makes a lot of sense, sometimes, to work with scaled integers.

I recall a friend of mine had some problem at work reconciling some fraction-of-a-yen discrepancy to do with interest paid - so, not just fractions, but exponentials too. AIUI, one reason the HP15C calculator is so popular in finance is that its results are taken as gospel - the HP15C's algorithms are the definition of what to calculate and how to round.

It's a mistake to think that what's going on in calculation is arithmetic. It's related, but calculations can behave very differently to the way numbers behave.


Top
 Profile  
Reply with quote  
PostPosted: Sat Dec 16, 2017 5:33 am 
Offline
User avatar

Joined: Thu May 28, 2009 9:46 pm
Posts: 8414
Location: Midwestern USA
Martin_H wrote:
Too funny.

Base-2 floating point numbers are pretty terrible for decimal financial calculations. After your computation you usually have some fiddly oddball number like 234.99999995 due to truncation errors. While approximately correct it needs to be massaged to eliminate errors. So you add back machine epsilon (e.g. 2^−24) and truncate at the last digit to eliminate those fiddly odd ball digits. So truncate(234.99999995 + 2^−24) would yield 235.0000000.

I seem to recall some programming languages having builtin functions to handle this in a machine independent manner.

This is where BCD numbers come in handy.

_________________
x86?  We ain't got no x86.  We don't NEED no stinking x86!


Top
 Profile  
Reply with quote  
PostPosted: Sat Dec 16, 2017 5:34 am 
Offline
User avatar

Joined: Thu May 28, 2009 9:46 pm
Posts: 8414
Location: Midwestern USA
BigEd wrote:
As for the odd bill, best to overpay, or you'd be in debt for a fraction of a cent and might be pursued to the ends of the earth.
floobydust wrote:
Can you write them a check for payment?? :mrgreen:

The check's in the mail! :lol:

_________________
x86?  We ain't got no x86.  We don't NEED no stinking x86!


Top
 Profile  
Reply with quote  
PostPosted: Mon Dec 18, 2017 5:16 am 
Offline

Joined: Sat Dec 13, 2003 3:37 pm
Posts: 1004
Pretty sure you can pay that kind of amount easily with Bitcoin...


Top
 Profile  
Reply with quote  
PostPosted: Mon Dec 18, 2017 1:12 pm 
Offline
User avatar

Joined: Wed Aug 17, 2005 12:07 am
Posts: 1228
Location: Soddy-Daisy, TN USA
whartung wrote:
Pretty sure you can pay that kind of amount easily with Bitcoin...



Every time I hear about Bitcoin, I want to kick myself...when I think back to the first time I ever heard about Bitcoin and it was something crazy like hundreds of Bitcoins for a dollar or something like that. If I had just invested a few hundred at the time....ugh.

_________________
Cat; the other white meat.


Top
 Profile  
Reply with quote  
PostPosted: Mon Dec 18, 2017 1:15 pm 
Offline
User avatar

Joined: Thu Dec 11, 2008 1:28 pm
Posts: 10949
Location: England
But you would surely have sold at $10, if not at $3... there are infinitely many bets we didn't take which we now know would have been winners...


Top
 Profile  
Reply with quote  
PostPosted: Wed Jan 17, 2018 3:34 pm 
Offline

Joined: Thu Feb 10, 2011 3:14 am
Posts: 79
Looks to me like it's using the CBM Basic floating point routines.


Top
 Profile  
Reply with quote  
PostPosted: Wed Mar 21, 2018 3:13 am 
Offline

Joined: Wed Mar 02, 2016 12:00 pm
Posts: 343
CurtisP wrote:
Looks to me like it's using the CBM Basic floating point routines.


Someone fixed that bug: http://sleepingelephant.com/ipw-web/bulletin/bb/viewtopic.php?f=2&t=6772


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

All times are UTC


Who is online

Users browsing this forum: No registered users and 14 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: