Invalid Floating Point Operation (DMD 2067)

ref2401 via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Thu Apr 16 07:23:08 PDT 2015


Hi Everyone,

After I switched to DMD 2067 my code that previously worked began 
crashing.
If I change the return statement in the matrixOrtho function

from:
	return Matrix(...);
to:
	Matrix m = Matrix(...);
	return m;

then the error won't occur anymore. What is going on?

Thank you.

import std.math;
import std.stdio;

struct Matrix {
	float m00, m01, m02, m03;
	float m10, m11, m12, m13;
	float m20, m21, m22, m23;
	float m30, m31, m32, m33;

	this(float m00, float m01, float m02, float m03,
		 float m10, float m11, float m12, float m13,
		 float m20, float m21, float m22, float m23,
		 float m30, float m31, float m32, float m33) nothrow pure @nogc 
{

		 this.m00 = m00; this.m01 = m01; this.m02 = m02; this.m03 = m03;
		 this.m10 = m10; this.m11 = m11; this.m12 = m12; this.m13 = m13;
		 this.m20 = m20; this.m21 = m21; this.m22 = m22; this.m23 = m23;
		 this.m30 = m30; this.m31 = m31; this.m32 = m32; this.m33 = m33;
	 }
}

void main(string[] args) {

	float width = 800f;
	float height = 600f;
	float near = -5f;
	float far = 10f;

	float hw = width / 2f;
	float hh = height / 2f;

	Matrix ortho = matrixOrtho(-hw, hw, -hh, hh, near, far);
}

Matrix matrixOrtho(float left, float right, float bottom, float 
top, float near, float far) /* pure @nogc */ {
	debug {
		FloatingPointControl fpCtrl;
		fpCtrl.enableExceptions(FloatingPointControl.severeExceptions);
	}

	float doubledNear = near*2f;
	float farMinusNear = far - near;
	float rightMinusLeft = right - left;
	float topMinusBottom = top - bottom;
	

	return Matrix(2f / rightMinusLeft, 0f, 0f, -(right + 
left)/rightMinusLeft,
		0f, 2f / topMinusBottom, 0f, -(top + bottom)/topMinusBottom,
		0f, 0f, -2f / farMinusNear, -(far + near)/farMinusNear,
		0f, 0f, 0f, 1f);

	//Matrix m = Matrix(2f / rightMinusLeft, 0f, 0f, -(right + 
left)/rightMinusLeft,
	//	0f, 2f / topMinusBottom, 0f, -(top + bottom)/topMinusBottom,
	//	0f, 0f, -2f / farMinusNear, -(far + near)/farMinusNear,
	//	0f, 0f, 0f, 1f);

	//return m;
}


Error report:

object.Error@(0): Invalid Floating Point Operation
----------------
0x00402340
0x004020E2
0x004029E2
0x004029B7
0x004028CF
0x004022D7
0x758D7C04 in BaseThreadInitThunk
0x77ADB54F in RtlInitializeExceptionChain
0x77ADB51A in RtlInitializeExceptionChain
object.Error@(0): Invalid Floating Point Operation
----------------
0x00402340
0x004020E2
0x004029E2
0x004029B7
0x004028CF
0x004022D7
0x758D7C04 in BaseThreadInitThunk
0x77ADB54F in RtlInitializeExceptionChain
0x77ADB51A in RtlInitializeExceptionChain
object.Error@(0): Invalid Floating Point Operation
----------------
0x00406E5B
0x004029C5
0x004028CF
0x004022D7
0x758D7C04 in BaseThreadInitThunk
0x77ADB54F in RtlInitializeExceptionChain
0x77ADB51A in RtlInitializeExceptionChain


More information about the Digitalmars-d-learn mailing list