D
dada
Consider the following function...
/**
***********************************************************************
* COMM_convertFreqIntToDouble
***********************************************************************
*
* \Description: Converts a frequency (integer in Hz) to a
* double in mHz.
*
* \Parameters: in int freqHz - the frequency in Hz
*
* \Returns: double - the representation(in mHz) of the frequency as
a double
*
* \Limitations:
*
***********************************************************************
*/
double COMM_convertFreqIntToDouble ( UINT32 freqHz )
{
double temp = freqHz / 1000.0 / 1000.0 ;
int tempint ;
/* Convert it back and see if they match ! */
tempint = (int) ( temp * 1000 * 1000 ) ;
if ( freqHz != tempint )
{
LOGMSG ( "WARNING", __FUNCTION__,"No Match",
"%d != %d", (unsigned int) freqHz, tempint ) ;
}
return ( temp ) ;
}
LOGMSG is a macro that performs some formatting and writes a message to
the console.
When this functin is called with
130075000
tempint = 130074999
Which causes the warning to be issued.
As I write this I see that I should be debugging and looking at the
double to see if it did indeed convert correctly...
Well, I'll ask my question anyways...
Is the difference being introduced in the conversion TO double or FROM
double, and, is there a better way to perform this operation ?
Thanks !
Joe
/**
***********************************************************************
* COMM_convertFreqIntToDouble
***********************************************************************
*
* \Description: Converts a frequency (integer in Hz) to a
* double in mHz.
*
* \Parameters: in int freqHz - the frequency in Hz
*
* \Returns: double - the representation(in mHz) of the frequency as
a double
*
* \Limitations:
*
***********************************************************************
*/
double COMM_convertFreqIntToDouble ( UINT32 freqHz )
{
double temp = freqHz / 1000.0 / 1000.0 ;
int tempint ;
/* Convert it back and see if they match ! */
tempint = (int) ( temp * 1000 * 1000 ) ;
if ( freqHz != tempint )
{
LOGMSG ( "WARNING", __FUNCTION__,"No Match",
"%d != %d", (unsigned int) freqHz, tempint ) ;
}
return ( temp ) ;
}
LOGMSG is a macro that performs some formatting and writes a message to
the console.
When this functin is called with
130075000
tempint = 130074999
Which causes the warning to be issued.
As I write this I see that I should be debugging and looking at the
double to see if it did indeed convert correctly...
Well, I'll ask my question anyways...
Is the difference being introduced in the conversion TO double or FROM
double, and, is there a better way to perform this operation ?
Thanks !
Joe