* Quick_Start: * --- * import stdxdecimal; * * void main() * { * auto d1 = decimal("1.23E-10"); * d1 -= decimal("2.00E-10"); * assert(d1.toString() == "-0.000000000077"); * } * --- * * This module defines an exact decimal type, Decimal, to a specific number of digits. * This is designed to be a drop in replacement for built-in floating point numbers, * allowing all the same possible operations. * * Floating point numbers (float, double, real) are inherently inaccurate because * they cannot represent * all possible numbers with a decimal part. Decimal on the other hand, is able to * represent all possible numbers with a decimal part (limited by memory size and Hook). * * Adapted from the specification of the * General Decimal Arithmetic. * * Custom_Behavior: * The behavior of Decimal is controlled by the template parameter Hook, * which can be a user defined type or one of the Hooks provided by this * module. * * The following behaviors are controlled by Hook: * *
*
*
*
*
* * The following predefined Hooks are available: * *
Abort | precision is set to 9, rounding is HalfUp, and the program * will assert(0) on divsion by zero, overflow, underflow, and * invalid operations. * |
Throw | precision is set to 9, rounding is HalfUp, and the program * will throw an exception on divsion by zero, overflow, underflow, and * invalid operations. * |
HighPrecision | precision is set to 64, rounding is HalfUp, and the program * will assert(0) on divsion by zero, overflow, underflow, and * invalid operations. * |
NoOp | precision is set to 9, rounding is HalfUp, and nothing will * happen on exceptional conditions. * |
* * Percision_and_Rounding: * Decimal accurately stores as many as Hook.precision significant digits. * Once the number of digits > Hook.precision, then the number is rounded. * Rounding is performed according to the rules laid out in RoundingMode. * * By default, the precision is 9, and the rounding mode is RoundingMode.HalfUp. * * Hook.precision must be <= uint.max - 1 and > 1. * * Note_On_Speed: * The more digits of precision you define in hook, the slower many operations * will become. It's recommended that you use the least amount of precision * necessary for your code. * * Exceptional_Conditions: * Certain operations will cause a Decimal to enter into an invalid state, * e.g. dividing by zero. When this happens, Decimal does two things * *
*
*
* * The following table lists all of the conditions * *
* * Each function documentation lists the specific states that will led to one * of these flags. * * Differences_From_The_Specification: *
*
*
*
* * Version: * v0.5. Still work in progress. For missing features, see README.md * * License: * Boost License 1.0. * * Authors: * Jack Stouffer