Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Officially goin out of my mind. Trivial INT problem
#11
(10-31-2022, 05:32 PM)bplus Wrote: .1 decimal =
.00011 repeat 0011 forever (can't draw a bar over top of 0011)


like 1/3 = .3 with bar ontop of 3.

Another question solved with string math! ;-))

Just having fun, I know we can't do "bars on top" with our binary computers.

Question solved -- it's *impossible* to represent 0.1 *perfectly* in floating point values!

Which goes to also answer your question of:  "Why y not 35.5100000000000000?"  

It's just one of those impossible representations in binary math.  As you said, we can't *truly* represent 1/3 in decimal math (at least not without the use of a repeater bar), and we can't represent the value of 35.51 perfectly either.  It's an imprecise value and thus gives imprecision errors when used.  It's just the nature of floating point values and imprecise fractions.

A much better solution is to keep everything as INTEGER values and then divide by 100 only at the display time for the end user.  Instead of working with 35.51, work with 3551.  Count pennies, not dollars, and you can avoid a vast majority of these problems.  Wink
Reply
#12
We can say .1 in Binary is 1/1010 in Binary ie express as ratio of 2 Integers like we do with 1/3 in decimal.
  724  855  599  923  575  468  400  206  147  564  878  823  652  556 bxor cross forever
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Int ( money ) inc 5 436 11-30-2025, 12:45 AM
Last Post: hsiangch_ong
  Big problem for me. MystikShadows 11 1,912 01-16-2025, 05:11 AM
Last Post: JRace
  Problem with "MOD" Kernelpanic 5 988 01-06-2025, 02:37 AM
Last Post: Pete
  Problem with _Resize dano 7 1,218 10-22-2024, 07:22 PM
Last Post: dano
  Menu Run (No EXE) Problem GareBear 5 1,135 10-06-2023, 05:41 AM
Last Post: GareBear

Forum Jump:


Users browsing this thread: 1 Guest(s)