Thrown when using Throw and division by zero occurs
Thrown when using Throw and an invalid operation occurs
Thrown when using Throw and overflow occurs
Thrown when using Throw and underflow occurs
Controls what happens when the number of significant digits exceeds Hook.precision
Factory function
Will halt program on division by zero, invalid operations, overflows, and underflows.
A exact decimal type, accurate to Hook.precision digits. Designed to be a drop in replacement for floating points.
Same as abort, but offers 64 significant digits
Does nothing on invalid operations except the proper flags
Will throw exceptions on division by zero, invalid operations, overflows, and underflows
* 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 number of significant digits to store.
- The rounding method.
- The min and max exponents.
- What to do when exceptional conditions arise.
*
*
*
*
* * The following predefined Hooks are available: * *
*
*
*
*
*
*
*
*
*
*
*
*
* * 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 * *
*- Sets a public bool variable to true.
- Calls a specific function in Hook, if it exists, with the
* operation's result as the only parameter.
*
*
* * 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: *
*- There's no concept of a Signaling NaN in this module.
- There's no concept of a Diagnostic NaN in this module.
- compare, implemented as opCmp, does not propagate NaN due
* to D's opCmp semantics.
*
*
*
* * Version: * v0.5. Still work in progress. For missing features, see README.md * * License: * Boost License 1.0. * * Authors: * Jack Stouffer