floating-WTF

sclytrack sclytrack at fake.com
Tue Jan 24 07:20:58 PST 2012



void calculate2(float a, float b)
{
	float s1 = 1.0 - a;
	float s2 = a * b;
	writeln(s2);
	writeln(a * b);
}

----------------
Output:
t*b= 0
t*b= 1.5
----------------


	assume	CS:.text._D4main10calculate2FffZv
_D4main10calculate2FffZv:
		push	RBP
		mov	RBP,RSP
		sub	RSP,020h
		movss	-010h[RBP],XMM0
		movss	-8[RBP],XMM1
		mov	RAX,03FF0000000000000h
		mov	-020h[RBP],RAX
		movsd	XMM2,-020h[RBP]
		cvtss2sd	XMM1,XMM1
		subsd	XMM2,XMM1
------conversion but xmm2 is no longer used
		cvtsd2ss	XMM2,XMM2
------precision error multiplication
		mulss	XMM1,XMM0
		movss	-018h[RBP],XMM1
		movss	XMM0,-018h[RBP]
		call	  _D3std5stdio14__T7writelnTfZ7writelnFfZv at PC32
		movss	XMM0,-8[RBP]
		movss	XMM1,-010h[RBP]
		mulss	XMM0,XMM1
		call	  _D3std5stdio14__T7writelnTfZ7writelnFfZv at PC32
		leave
		ret
		nop
		nop
		nop

------------
DMD64 D Compiler v2.057
Ubuntu 11.10


More information about the Digitalmars-d-learn mailing list