Download Reference Manual
The Developer's Library for D
About Wiki Forums Source Search Contact

Ticket #524: Float_sign.patch

File Float_sign.patch, 0.9 kB (added by Deewiant, 1 year ago)
  • Float.d

    old new  
    2727 
    2828private import Integer = tango.text.convert.Integer; 
    2929 
     30private import tango.math.IEEE : signbit; 
     31 
    3032private alias real NumType; 
    3133 
    3234private extern (C) NumType log10l(NumType x); 
     
    134136                return digit + '0'; 
    135137        } 
    136138 
    137         if (x !<>= x) 
    138             return "nan"; 
    139  
    140         if (x is x.infinity) 
    141             return "inf"; 
    142  
    143         int exp; 
    144139        bool sign; 
    145140 
    146141        // extract the sign 
    147         if (x < 0.0
     142        if (signbit(x)
    148143           { 
    149144           x = -x; 
    150145           sign = true; 
    151146           } 
    152147 
     148        if (x !<>= x) 
     149            return cast(T[])(sign ? "-nan" : "nan"); 
     150 
     151        if (x is x.infinity) 
     152            return cast(T[])(sign ? "-inf" : "inf"); 
     153 
     154        int exp; 
     155 
    153156        // don't scale if zero 
    154157        if (x > 0.0) 
    155158           {