Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Steve's Programming Challenge: Weights and Measures
#10
(08-16-2024, 12:52 AM)Jack Wrote: Steve, I agree with you but most of the time floating-point math works surprisingly well, but then you have cases where it fails catastrophically

Aye.  Folks just need to realize *WHY* it tends to fail, when it does.

FOR i = 1 TO 100 STEP 0.1
   PRINT i
NEXT

^That's *going* to have issues in it, just for the simple fact that we're adding 0.1 -- a number we can't represent perfectly -- over and over in that loop, which compounds the level of error until it's quite noticeable.  It's not a flaw in QB64.  It's not a glitch in the matrix.  There's no "Fix" for it.   That's just life with floating point values.  They're fast -- but they're imprecise.

If one needs precision, use integer values (Loop from 10 to 1000 and divide by 10).  It's why banks track money by pennies and not dollars.  You have 12345 pennies in the bank, not $123.45 dollars.   The dollars is just formatted at the PRINT end, to make it easier for people to understand and relate to.  Internally, it's all pennies.  Smile
Reply


Messages In This Thread
RE: Steve's Programming Challenge: Weights and Measures - by SMcNeill - 08-16-2024, 01:01 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Steve is on vacation SMcNeill 9 970 11-06-2025, 06:55 PM
Last Post: TempodiBasic
  personal coding challenge results James D Jarvis 4 628 06-20-2025, 03:20 PM
Last Post: James D Jarvis
  QB64PE programming challenge? auto-convert image to photoreal etch-a-sketch drawing madscijr 9 1,884 02-14-2025, 05:49 PM
Last Post: madscijr
  For what it’s worth: Programming Clarity PhilOfPerth 11 2,286 07-27-2024, 03:15 PM
Last Post: bplus
  Vintage programming BigPete 4 902 05-15-2024, 09:57 AM
Last Post: BigPete

Forum Jump:


Users browsing this thread: 1 Guest(s)