weird behavior for machine epsilon in float, double and real

Andrew Spott andrew.spott at gmail.com
Fri Apr 10 22:22:39 PDT 2009


So, for the following code, I get something I think is a little off.  I get the same value for all three variable types.  I'm kind of new to this, but I would think that a 32 bit would give me a different "smallest value" than a 64 bit or 80 bit (if real even evaluates to 80 bit on my machine).

What am I doing wrong, or is this a bug?

import std.stdio;

void main() {

	//Find Machine Epsilon:

	double ep = 1.0;
	double n = 1.0;

	while (ep + n != n) {
		ep = ep / 2;
	}

	writefln(ep);

	real epr = 1.0;
	real nr = 1.0;

	while (epr + nr != nr)
		epr = epr / 2;

	writefln(epr);
		
	float epf = 1.0;
	float nf = 1.0;

	while (epf + nf != nf)
		epf = epf / 2;

	writefln(epr);
}



More information about the Digitalmars-d mailing list