home bbs files messages ]

Forums before death by AOL, social media and spammers... "We can't have nice things"

   comp.arch      Apparently more than just beeps & boops      131,241 messages   

[   << oldest   |   < older   |   list   |   newer >   |   newest >>   ]

   Message 130,779 of 131,241   
   Anton Ertl to Stefan Monnier   
   Re: floating point history, word order a   
   05 Jan 26 17:40:15   
   
   From: anton@mips.complang.tuwien.ac.at   
      
   Stefan Monnier  writes:   
   >> If you look at Java's BigDecimal operations   
   >> ,   
   >> they all have versions without and width MathContext (which includes a   
   >> target scale and a rounding mode), and sometimes additional variants   
   >> (e.g., divide() has variants where you pass just the rounding mode, or   
   >> the rounding mode and scale individually instead of through a   
   >> MathContext).   
   >   
   >I wonder how that would compare in practice with a Rational type, where   
   >all arithmetic operations are exact (and thus don't need anything like   
   >a MathContext) and you simply provide a rounding function that takes   
   >two argument: a "target scale" (in the form of a target denominator) and   
   >a rounding mode.   
      
   BigDecimal is almost like what you imagine, except that the   
   denominators are always powers of 10.  Without MathContext addition,   
   subtraction, and multiplication are exact, and division is also exact   
   or produces an exception.   
      
   The MathContext consists of the target scale and the rounding mode.   
      
   Proper rational arithmetics (used in IIRC Prolog II) is also exact for   
   division (and has no rounding), but you can get really long numerators   
   and denominators.   
      
   >[ Extra points for implementing compiler optimizations that keep track   
   >  of the denominators statically to try and do away with the   
   >  denominators at run-time as much as possible.   
      
   For the kind of fixed point used for financial calculation rules, the   
   scale of every calculation is statically known (it comes out of the   
   rules), so a compiler for a programming language that has such fixed   
   point numbers as native type (Cobol, Ada, anything else?) does not   
   need to check every time whether rescaling is necessary (which   
   probably happens for Java's BigDecimal).   
      
   >  Maybe also figure out   
   >  how to eliminate the use of bignums for the numerators.   
      
   I don't think that's possible if the language specifies   
   arbitrary-precision-arithmetics, because the program processes input   
   data that ios coming from data sources that can contain   
   arbitrarily-large numbers.   
      
   What is possible, and is done in various dynamically-typed languages   
   is to have the common case (a bignum that's actually small) unbox, and   
   use boxing only in those cases where the number exceeds the range of   
   unboxed numbers.  I have looked at the OpenJDK BigInteger   
   implementation, and there the BigInteger is always boxed (as is   
   everything else in Java that is an object).   
      
   - anton   
   --   
   'Anyone trying for "industrial quality" ISA should avoid undefined behavior.'   
     Mitch Alsup,    
      
   --- SoupGate-Win32 v1.05   
    * Origin: you cannot sedate... all the things you hate (1:229/2)   

[   << oldest   |   < older   |   list   |   newer >   |   newest >>   ]


(c) 1994,  bbs@darkrealms.ca