1 <html> 2 <!-- 3 Licensed to the Apache Software Foundation (ASF) under one or more 4 contributor license agreements. See the NOTICE file distributed with 5 this work for additional information regarding copyright ownership. 6 The ASF licenses this file to You under the Apache License, Version 2.0 7 (the "License"); you may not use this file except in compliance with 8 the License. You may obtain a copy of the License at 9 10 http://www.apache.org/licenses/LICENSE-2.0 11 12 Unless required by applicable law or agreed to in writing, software 13 distributed under the License is distributed on an "AS IS" BASIS, 14 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 See the License for the specific language governing permissions and 16 limitations under the License. 17 --> 18 <!-- $Revision: 992696 $ $Date: 2010-09-05 00:57:31 +0200 (dim. 05 sept. 2010) $ --> 19 <body> 20 Decimal floating point library for Java 21 22 <p>Another floating point class. This one is built using radix 10000 23 which is 10<sup>4</sup>, so its almost decimal.</p> 24 25 <p>The design goals here are: 26 <ol> 27 <li>Decimal math, or close to it</li> 28 <li>Settable precision (but no mix between numbers using different settings)</li> 29 <li>Portability. Code should be keep as portable as possible.</li> 30 <li>Performance</li> 31 <li>Accuracy - Results should always be +/- 1 ULP for basic 32 algebraic operation</li> 33 <li>Comply with IEEE 854-1987 as much as possible. 34 (See IEEE 854-1987 notes below)</li> 35 </ol></p> 36 37 <p>Trade offs: 38 <ol> 39 <li>Memory foot print. I'm using more memory than necessary to 40 represent numbers to get better performance.</li> 41 <li>Digits are bigger, so rounding is a greater loss. So, if you 42 really need 12 decimal digits, better use 4 base 10000 digits 43 there can be one partially filled.</li> 44 </ol></p> 45 46 <p>Numbers are represented in the following form: 47 <pre> 48 n = sign × mant × (radix)<sup>exp</sup>;</p> 49 </pre> 50 where sign is ±1, mantissa represents a fractional number between 51 zero and one. mant[0] is the least significant digit. 52 exp is in the range of -32767 to 32768</p> 53 54 <p>IEEE 854-1987 Notes and differences</p> 55 56 <p>IEEE 854 requires the radix to be either 2 or 10. The radix here is 57 10000, so that requirement is not met, but it is possible that a 58 subclassed can be made to make it behave as a radix 10 59 number. It is my opinion that if it looks and behaves as a radix 60 10 number then it is one and that requirement would be met.</p> 61 62 <p>The radix of 10000 was chosen because it should be faster to operate 63 on 4 decimal digits at once instead of one at a time. Radix 10 behavior 64 can be realized by add an additional rounding step to ensure that 65 the number of decimal digits represented is constant.</p> 66 67 <p>The IEEE standard specifically leaves out internal data encoding, 68 so it is reasonable to conclude that such a subclass of this radix 69 10000 system is merely an encoding of a radix 10 system.</p> 70 71 <p>IEEE 854 also specifies the existence of "sub-normal" numbers. This 72 class does not contain any such entities. The most significant radix 73 10000 digit is always non-zero. Instead, we support "gradual underflow" 74 by raising the underflow flag for numbers less with exponent less than 75 expMin, but don't flush to zero until the exponent reaches MIN_EXP-digits. 76 Thus the smallest number we can represent would be: 77 1E(-(MIN_EXP-digits-1)*4), eg, for digits=5, MIN_EXP=-32767, that would 78 be 1e-131092.</p> 79 80 <p>IEEE 854 defines that the implied radix point lies just to the right 81 of the most significant digit and to the left of the remaining digits. 82 This implementation puts the implied radix point to the left of all 83 digits including the most significant one. The most significant digit 84 here is the one just to the right of the radix point. This is a fine 85 detail and is really only a matter of definition. Any side effects of 86 this can be rendered invisible by a subclass.</p> 87 </body> 88 </html> 89