J
Jon Ripley
Hi,
This function should return the integer portion of a float truncating
down to -infinity. Where int64(12.34) = 12 and int64(-12.34) = -13 but
int64(-12) = -12.
In reality the function is called with a pointer to a double.
void int64 ( double *num )
{
double tmp;
tmp=(long)*num;
if ((tmp < 0) && (*num != tmp))
*num=tmp-1;
else
*num=tmp;
}
When given any positive number it works, when given any non-integer
negative number it works. When given a negative integer it always
returns zero.
I'm stuck, I can't get it to return correct data in the last case.
This is one of many routines I am writing to manipulate the integer
portions of 64-bit floats.
Another:
double mod64(double *x, double *y)
{
return (double)((long)*x % (long)*y));
}
Just causes the calling routine to abort rather messily.
Please help!
TIA,
Jon R.
--
This function should return the integer portion of a float truncating
down to -infinity. Where int64(12.34) = 12 and int64(-12.34) = -13 but
int64(-12) = -12.
In reality the function is called with a pointer to a double.
void int64 ( double *num )
{
double tmp;
tmp=(long)*num;
if ((tmp < 0) && (*num != tmp))
*num=tmp-1;
else
*num=tmp;
}
When given any positive number it works, when given any non-integer
negative number it works. When given a negative integer it always
returns zero.
I'm stuck, I can't get it to return correct data in the last case.
This is one of many routines I am writing to manipulate the integer
portions of 64-bit floats.
Another:
double mod64(double *x, double *y)
{
return (double)((long)*x % (long)*y));
}
Just causes the calling routine to abort rather messily.
Please help!
TIA,
Jon R.
--