btSqrt Approximation Problem

User avatar
sio2interactive
Posts: 31
Joined: Tue Jul 29, 2008 10:26 am

btSqrt Approximation Problem

Post by sio2interactive »

The following code on btSqrt in btScalar.h when using approximation doesn't work on MacOS (well partially work), sometimes I get NAN as the result of the function:

Code: Select all


    double x, z, tempf;
    unsigned long *tfptr = ((unsigned long *)&tempf) + 1;

	tempf = y;
	*tfptr = (0xbfcdd90a - *tfptr)>>1; 
	x =  tempf;
	z =  y*btScalar(0.5);                    
	x = (btScalar(1.5)*x)-(x*x)*(x*z);        
	x = (btScalar(1.5)*x)-(x*x)*(x*z);
	x = (btScalar(1.5)*x)-(x*x)*(x*z);
	x = (btScalar(1.5)*x)-(x*x)*(x*z);
	x = (btScalar(1.5)*x)-(x*x)*(x*z);
	return x*y;

Is there a way to fix this?
User avatar
Erwin Coumans
Site Admin
Posts: 4221
Joined: Sun Jun 26, 2005 6:43 pm
Location: California, USA

Re: btSqrt Approximation Problem

Post by Erwin Coumans »

This code is never enabled, is it? Who defines USE_APPROXIMATION?

We better just remove it, and just use sqrtf.
Thanks,
Erwin