|
On Forth, there's the philosophy of the fixed point: https://www.forth.com/starting-forth/5-fixed-point-arithmeti... With 32 and 64 bit numbers, you can just scale decimals up.
So, Torvalds was right. On dangerous contexts (uper-precise medical doses, FP
has good reasons to exist, and I am not completely sure). Also, both Forth and Lisp internally suggest to use represented rationals before floating point numbers. Even toy lisps from https://t3x.org have rationals too. In Scheme, you have both exact->inexact and inexact->exact which convert rationals to FP and viceversa. If you have a Linux/BSD distro, you may already have Guile installed as a dependency. Hence, run it and then: scheme@(guile-user)> (inexact->exact 2.5)
$2 = 5/2
scheme@(guile-user)> (exact->inexact (/ 5 2))
$3 = 2.5
Thus, in Forth, I have a good set of q{+,-,*,/} operations for rational (custom coded, literal four lines) and they work great for a good 99% of the cases.As for irrational numbers, NASA used up 16 decimals, and the old 113/355 can be precise enough for a 99,99 of the pieces built in Earth. Maybe not for astronomical distances, but hey... In Scheme: scheme@(guile-user)> (exact->inexact (/ 355 113))
$5 = 3.1415929203539825
In Forth, you would just use : pi* 355 133 m*/ ;
with a great precision for most of the objects being measured against. |