digitalmars.D - double.min - should be 5e-324?
- Dmitry Olshansky <dmitry.olsh gmail.com> Dec 04 2010
- so <so so.do> Dec 04 2010
- so <so so.do> Dec 04 2010
- Dmitry Olshansky <dmitry.olsh gmail.com> Dec 04 2010
- Dmitry Olshansky <dmitry.olsh gmail.com> Dec 04 2010
- Ellery Newcomer <ellery-newcomer utulsa.edu> Dec 04 2010
- sybrandy <sybrandy gmail.com> Dec 04 2010
- Don <nospam nospam.com> Dec 04 2010
- Don <nospam nospam.com> Dec 04 2010
- Dmitry Olshansky <dmitry.olsh gmail.com> Dec 05 2010
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
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
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
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
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
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
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
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
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
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
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









so <so so.do> 