News for hackers. Stuff that matters.
Re:Beware of Fast-Math by outurnate on Saturday May 31, 2025 @10:20AM (#44144446)
You're better off representing values as rationals; a ratio between two different numbers. For example, 0.0375 would be represented as 375 over 10000, or 3 over 80
Re:Beware of Fast-Math by simonw on Saturday May 31, 2025 @10:38AM (#44144575)
Sounds hard to model in SQLite.
Re:Beware of Fast-Math by freeone3000 on Saturday May 31, 2025 @11:35AM (#44144939)
You need two fields, a numerator and a denominator. The denominator can stay fixed as long as openapi’s billing stays fixed.
Re:Beware of Fast-Math by teaearlgraycold on Saturday May 31, 2025 @11:38AM (#44144961)
Two columns?
Re:Beware of Fast-Math by anthk on Saturday May 31, 2025 @02:05PM (#44145933)
From Forth, here's how I'd set the rationals:

    : gcd begin dup while tuck mod repeat drop ;
    : lcm 2dup \* abs -rot gcd / ;
    : reduce 2dup gcd tuck / >r / r> ;
    : q+ rot 2dup \* >r rot \* -rot \* + r> reduce ;
    : q- swap negate swap q+ ;
    : q\* rot \* >r  \* r> reduce ;
    : q/ >r \* swap r> \* swap reduce ;
Example: to compute 70 * 0.25 = 35/2

70 1 1 4 q* reduce .s 35 2 ok

On stack managing words like 2dup, rot and such, these are easily grasped under either Google/DDG or any Forth with the words "see" and/or "help".

as a hint, q- swaps the top two numbers in the stack, (which compose a rational), makes the last one negative and then turns back its position. And then it calls q+.

So, 2/5 - 3/2 = 2/5 + -3/2.