c语言mod函数,modf ( )【C语言库函数源代码】

  • Post author:
  • Post category:其他


【C语言库函数源代码】

【本程序在Dev C++ 4.9.9.2 下编译通过】

/*

将浮点数x分解成整数部分和小数部分。

返回小数部分,将整数部分存入* iptr所指内存中。

*/

doublemy_modf01(double x, double *iptr)

{

double ret =

fmod(x,1.0);

*iptr = x – ret;

return ret;

}//这个函数算法比较简单,也容易让人理解。

//下面的这个函数理解起来就有点困难了。

typedefstruct

{

unsigned int mantissal:32;

unsigned int mantissah:20;

unsigned int exponent:11;

unsigned int sign:1;

}double_t;//这个结构体在IEEE.h定义。

doublemy_modf02(double x, double *y)

{

double_t * z = (double_t *)&x;

double_t * iptr = (double_t *)y;

int j0;

unsigned int i;

j0 = z->exponent – 0x3ff;/* exponent of x */

if(j0<20)

{/* integer part in

high x */

if(j0<0)