any integral, char, bool, floating point, decimal, string or character range _value Exceptions:
Data type | Invalid | Overflow | Underflow | Inexact |
---|---|---|---|---|
integral | ✓ | |||
char | ✓ | |||
float | ✓ | ✓ | ✓ | |
bool | ||||
decimal | ✓ | ✓ | ✓ | |
string | ✓ | ✓ | ✓ | ✓ |
range | ✓ | ✓ | ✓ | ✓ |
auto a = decimal32(112); //represented as 112 x 10^^0; auto b = decimal32(123456789); //inexact, represented as 1234568 * x 10^^2
auto a = decimal32(1.23); //inexact, represented as 123 x 10^^-2, //because floating point data cannot exactly represent 1.23 //in fact 1.23 as float is 1.230000019073486328125 auto b = decimal64(float.nan);
auto a = decimal32(decimal64(10)); auto b = decimal64(a); auto c = decimal64(decimal128.nan);
A _decimal value can be defined based on _decimal, scientific or hexadecimal representation:
auto d = decimal32("2.3456789") //internal representation will be 2.345679 //because decimal32 has a 7-digit precision
auto d1 = decimal64("0x00003p+21"); auto d2 = decimal64("3e+21"); assert (d1 == d2);
auto d1 = decimal32("123_456_789_123_456_789_123_456_789_123"); //30 digits //internal representation will be 1.234568 x 10^^30
auto d = decimal32("10"); //integral auto e = decimal64("125.43") //floating point auto f = decimal128("123.456E-32"); //scientific auto g = decimal32("0xABCDEp+21"); //hexadecimal 0xABCD * 10^^21 auto h = decimal64("NaN1234"); //$(B NaN) with 1234 payload auto i = decimal128("sNaN<0xABCD>") //signaling $(B NaN) with a 0xABCD payload auto j = decimal32("inf"); //infinity
These constructors are provided only from convenience, and to offer support for conversion function $(PHOBOS conv, to, to). Char values are cast to unsigned int. Bool values are converted to 0.0 (false) or 1.0 (true)
auto a = decimal32(true); //1.0 auto b = decimal32('a'); //'a' ascii code (97) auto c = to!decimal32(false); //phobos to!(bool, decimal32) auto d = to!decimal128('Z'); //phobos to!(char, decimal128)
Constructs a Decimal data type using the specified _value