From: bc@freeuk.com   
      
   On 24/11/2025 11:57, Michael S wrote:   
   > On Mon, 24 Nov 2025 11:45:18 +0000   
   > bart wrote:   
   >>   
   >> But my scripting language has an arbitrary-precision /decimal/   
   >> floating point type, which can also be used for pure integer   
   >> calculations.   
   >>   
   >   
   > Arbitrary-precision floating point? That sounds problematic, regardless   
   > of base. Unless you don't use the word 'arbitrary' in the same sense   
   > that it is used, for example, in GMP.   
   > Gnu MPFR is very careful to never call itself "arbitrary-precision" in   
   > official docs.   
   >   
      
   If you mean problems like repeated multiplies giving ever larger   
   numbers, then that will happen also with integers (or rationals).   
      
   If you mean the problems with a divide operation potentially carrying on   
   indefinitely, then a cap needs to be set on that.   
      
   I haven't attempted libraries for working out trancendental functions;   
   the problems there are in getting a particular precision even if you   
   know that in advance.   
      
   But for basic arithmetic, it works extremely well.   
      
   (While it is built-in to my scripting language, it was originally a   
   standalone library and has been ported to C. See the bignum.c and   
   bignum.h files here:   
      
   https://github.com/sal55/langs/tree/master/bignum   
      
   You can try out division like this:   
      
    #include    
    #include "bignum.h"   
      
    int main() {   
    Bignum a, b, c;   
      
    a = bn_makeint(1);   
    b = bn_makeint(7);   
    c = bn_init();   
      
    bn_div(c, a, b, 1000);   
    bn_println(c);   
    }   
      
   (Build as 'gcc prog.c bignum.c' etc.)   
      
   You can see that 'bn_div' needs a precision argument: this is the number   
   of significant decimal digits. Using 100M here produced 100 million   
   digits and took about 6 seconds.)   
      
   --- SoupGate-Win32 v1.05   
    * Origin: you cannot sedate... all the things you hate (1:229/2)   
|