"Fossies" - the Fresh Open Source Software Archive

Member "ldc-1.7.0-src/tests/d2/dmd-testsuite/runnable/imports/a12037.d" (5 Jan 2018, 2062 Bytes) of package /linux/misc/ldc-1.7.0-src.tar.gz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) D source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file.

    1 module imports.aXXXXX;
    2 
    3 auto min(A, B)(A a, B b) { return a < b ? a : b; }
    4 alias TypeTuple(T...) = T;
    5 
    6 private template CustomFloatParams(uint bits)
    7 {
    8     static if (bits ==  8) alias CustomFloatParams!( 4,  3) CustomFloatParams;
    9     static if (bits == 16) alias CustomFloatParams!(10,  5) CustomFloatParams;
   10     static if (bits == 32) alias CustomFloatParams!(23,  8) CustomFloatParams;
   11     static if (bits == 64) alias CustomFloatParams!(52, 11) CustomFloatParams;
   12     static if (bits == 80) alias CustomFloatParams!(64, 15) CustomFloatParams;
   13 }
   14 private template CustomFloatParams(uint precision, uint exponentWidth)
   15 {
   16     alias TypeTuple!(
   17         precision,
   18         exponentWidth,
   19     ) CustomFloatParams;
   20 }
   21 
   22 struct CustomFloat(uint precision, uint exponentWidth)
   23 if ((1 + precision + exponentWidth) % 8 == 0 && precision + exponentWidth > 0)
   24 {
   25 private:
   26     union ToBinary(F)
   27     if (is(typeof(CustomFloatParams!(F.sizeof*8))) || is(F == real))
   28     {
   29         F set;
   30 
   31         // If on Linux or Mac, where 80-bit reals are padded, ignore the
   32         // padding.
   33         CustomFloat!(CustomFloatParams!(min(F.sizeof*8, 80))) get;
   34 
   35         // Convert F to the correct binary type.
   36         static typeof(get) opCall(F value)
   37         {
   38             ToBinary r;
   39             r.set = value;
   40             return r.get;
   41         }
   42         alias get this;
   43     }
   44 
   45 public:
   46     @property bool sign() { return 1; }
   47     @property void sign(bool) {}
   48 
   49     this(F)(F input)
   50     if (__traits(compiles, cast(real)input))
   51     {
   52         this = input;
   53     }
   54 
   55     void opAssign(F)(F input)
   56     if (__traits(compiles, cast(real)input))
   57     {
   58         static if (is(F == float) || is(F == double) || is(F == real))
   59                 auto value = ToBinary!(F)(input);
   60         else    auto value = ToBinary!(real)(input);
   61 
   62         sign = value.sign;
   63     }
   64 
   65     @property F get(F)()
   66     if (is(F == float) || is(F == double) || is(F == real))
   67     {
   68         ToBinary!F result;
   69         return F.init;
   70     }
   71 
   72     T opCast(T)()
   73     if (__traits(compiles, get!T))
   74     {
   75         return get!T;
   76     }
   77 }