OT: denormals

Discussion of chess software programming and technical issues.

Moderators: hgm, Rebel, chrisw

mar
Posts: 2559
Joined: Fri Nov 26, 2010 2:00 pm
Location: Czech Republic
Full name: Martin Sedlak

OT: denormals

Post by mar »

Hi,
while this is not directly related to chessprogramming (sorry for that but I consider chess programmers very good, that's why I'm asking:), I have run into a weird problem.
I'm getting denormal floats when converting from very small (near-zero) doubles.
I always thought that x87 automatically fixes these to zero when doing fst(p).
Is there a way to work around it (I'm currently fixing this manually which is not what I would consider elegant). Compiler: MSVC, no SSE, floating point model: strict.
Has anyone ever experienced similar problems?

Thanks

Martin

EDIT:
sample code:

Code: Select all

float f;

int main()
{
	double d = -1e-300;
	f = (float)d;
	printf("f = %0.6f\n", f);
	if ( !f )
		f = 0.0f;
	printf("f = %0.6f\n", f);
	return 0;
}
prints:

Code: Select all

f = -0.000000
f = 0.000000
mar
Posts: 2559
Joined: Fri Nov 26, 2010 2:00 pm
Location: Czech Republic
Full name: Martin Sedlak

Re: OT: denormals

Post by mar »

Resolved: ok it's not denormal, it just preserves sign... Stupid me :) I would expect a positive zero though. But it seems IEEE requires both -0 and +0.