www.digitalmars.com         C & C++   DMDScript  

digitalmars.D - double.min - should be 5e-324?

reply Dmitry Olshansky <dmitry.olsh gmail.com> writes:
Well,  to keep things short, double.min returns something weird.
See the following for demonstration:
import std.stdio;

void main(){
     double r = double.max, r2 = double.min;
     writeln(r);//1.79769e+308
     r *= 2;//test if it's max
     writeln(r); // infinity, ok

     writeln(r2);//2.22507e-308, wtf ?
     r2 /= 2.0;
     writeln(r2);// 1.11254e-308, a logical consequence of above

     double dmin = 5e-324;
     writeln(dmin);// 4.94066e-324
     dmin /= 2.0;
     writefln(dmin);// 0
}

-- 
Dmitry Olshansky
Dec 04 2010
next sibling parent reply so <so so.do> writes:
 writeln(r2);//2.22507e-308, wtf ?

What is wrong? It is the smallest representable double. not (-double.max)
 r2 /= 2.0;
 writeln(r2);// 1.11254e-308, a logical consequence of above

That is something weird, you get a double smaller than the smallest representable! -- Using Opera's revolutionary email client: http://www.opera.com/mail/
Dec 04 2010
next sibling parent so <so so.do> writes:
See what you mean, but it is the standard value from c's float.h.

This is not my day, i should just stop posting...

-- 
Using Opera's revolutionary email client: http://www.opera.com/mail/
Dec 04 2010
prev sibling parent Dmitry Olshansky <dmitry.olsh gmail.com> writes:
On 05.12.2010 0:48, so wrote:
 writeln(r2);//2.22507e-308, wtf ?

What is wrong? It is the smallest representable double. not (-double.max)

The smallest is 5e-324 as I (hopefully) showed.
 r2 /= 2.0;
 writeln(r2);// 1.11254e-308, a logical consequence of above

That is something weird, you get a double smaller than the smallest representable!

To prove the above point. -- Dmitry Olshansky
Dec 04 2010
prev sibling next sibling parent Dmitry Olshansky <dmitry.olsh gmail.com> writes:
On 05.12.2010 0:22, Dmitry Olshansky wrote:
 Well,  to keep things short, double.min returns something weird.
 See the following for demonstration:
 import std.stdio;

 void main(){
     double r = double.max, r2 = double.min;
     writeln(r);//1.79769e+308
     r *= 2;//test if it's max
     writeln(r); // infinity, ok

     writeln(r2);//2.22507e-308, wtf ?
     r2 /= 2.0;
     writeln(r2);// 1.11254e-308, a logical consequence of above

     double dmin = 5e-324;
     writeln(dmin);// 4.94066e-324
     dmin /= 2.0;
     writefln(dmin);// 0
 }

writeln(dmin); //0 -- Dmitry Olshansky
Dec 04 2010
prev sibling next sibling parent reply Ellery Newcomer <ellery-newcomer utulsa.edu> writes:
On 12/04/2010 03:22 PM, Dmitry Olshansky wrote:
 Well, to keep things short, double.min returns something weird.
 See the following for demonstration:
 import std.stdio;

 void main(){
 double r = double.max, r2 = double.min;
 writeln(r);//1.79769e+308
 r *= 2;//test if it's max
 writeln(r); // infinity, ok

 writeln(r2);//2.22507e-308, wtf ?
 r2 /= 2.0;
 writeln(r2);// 1.11254e-308, a logical consequence of above

 double dmin = 5e-324;
 writeln(dmin);// 4.94066e-324
 dmin /= 2.0;
 writefln(dmin);// 0
 }

looks like double.min is returning double.min_normal oddly enough, double.min is undefined in the spec
Dec 04 2010
parent =?UTF-8?B?QWxpIMOHZWhyZWxp?= <acehreli yahoo.com> writes:
Ellery Newcomer wrote:
 looks like double.min is returning double.min_normal

 oddly enough, double.min is undefined in the spec

Yeah, things got changed a while back for floating point types. .min now returns the minimum normal. To get the actual minimum value, we need to use the negative of .max. Ali
Dec 04 2010
prev sibling next sibling parent sybrandy <sybrandy gmail.com> writes:
On 12/04/2010 04:22 PM, Dmitry Olshansky wrote:
 Well, to keep things short, double.min returns something weird.
 See the following for demonstration:
 import std.stdio;

 void main(){
 double r = double.max, r2 = double.min;
 writeln(r);//1.79769e+308
 r *= 2;//test if it's max
 writeln(r); // infinity, ok

 writeln(r2);//2.22507e-308, wtf ?
 r2 /= 2.0;
 writeln(r2);// 1.11254e-308, a logical consequence of above

 double dmin = 5e-324;
 writeln(dmin);// 4.94066e-324
 dmin /= 2.0;
 writefln(dmin);// 0
 }

Perhaps this link can help: https://secure.wikimedia.org/wikipedia/en/wiki/IEEE_754-1985 Casey
Dec 04 2010
prev sibling parent reply Don <nospam nospam.com> writes:
Dmitry Olshansky wrote:
 Well,  to keep things short, double.min returns something weird.
 See the following for demonstration:
 import std.stdio;
 
 void main(){
     double r = double.max, r2 = double.min;
     writeln(r);//1.79769e+308
     r *= 2;//test if it's max
     writeln(r); // infinity, ok
 
     writeln(r2);//2.22507e-308, wtf ?
     r2 /= 2.0;
     writeln(r2);// 1.11254e-308, a logical consequence of above
 
     double dmin = 5e-324;
     writeln(dmin);// 4.94066e-324
     dmin /= 2.0;
     writefln(dmin);// 0
 }
 

mentioned in the spec.
Dec 04 2010
parent reply Don <nospam nospam.com> writes:
Don wrote:
 Dmitry Olshansky wrote:
 Well,  to keep things short, double.min returns something weird.
 See the following for demonstration:
 import std.stdio;

 void main(){
     double r = double.max, r2 = double.min;
     writeln(r);//1.79769e+308
     r *= 2;//test if it's max
     writeln(r); // infinity, ok

     writeln(r2);//2.22507e-308, wtf ?
     r2 /= 2.0;
     writeln(r2);// 1.11254e-308, a logical consequence of above

     double dmin = 5e-324;
     writeln(dmin);// 4.94066e-324
     dmin /= 2.0;
     writefln(dmin);// 0
 }

mentioned in the spec.

And futher -- double.min_normal is the smallest normalised double. The smallest representable double is (double.min_normal * double.epsilon). double.min is a silly name, so it has been deprecated.
Dec 04 2010
parent Dmitry Olshansky <dmitry.olsh gmail.com> writes:
On 05.12.2010 8:59, Don wrote:
 Don wrote:
 Dmitry Olshansky wrote:
 Well,  to keep things short, double.min returns something weird.
 See the following for demonstration:
 import std.stdio;

 void main(){
     double r = double.max, r2 = double.min;
     writeln(r);//1.79769e+308
     r *= 2;//test if it's max
     writeln(r); // infinity, ok

     writeln(r2);//2.22507e-308, wtf ?
     r2 /= 2.0;
     writeln(r2);// 1.11254e-308, a logical consequence of above

     double dmin = 5e-324;
     writeln(dmin);// 4.94066e-324
     dmin /= 2.0;
     writefln(dmin);// 0
 }

not mentioned in the spec.

And futher -- double.min_normal is the smallest normalised double. The smallest representable double is (double.min_normal * double.epsilon). double.min is a silly name, so it has been deprecated.

I see, thanks for the explanation. -- Dmitry Olshansky
Dec 05 2010