Personal tools
You are here: Home Projects LISP Le_Lisp Source code lelisp11 ffp_modf.c
Document Actions

ffp_modf.c

by Paul McJones last modified 2007-01-02 09:26

Click here to get the file

Size 1.1 kB - File type text/x-csrc

File contents

typedef long ff; /*  fast floating   mantissa :24   sign :1   exp+64 :7  */
union float_ff { 
	float asfloat;
	long  aslong;
};
#define  reg  register

float  modf( val, intpart ) /*  12.3  ->  12.0  +  0.3   in *intpart, ret  */
union float_ff val;  
reg ff* intpart;
{       
	reg long  f  = val.aslong,   e;

	if( e = f & 0x7f )  e -= 64;
	if( e <= 0 ){
		*intpart = 0;  
		return  val .asfloat; 
	}
	if( e >= 24 ){
		*intpart = f;  
		return  0.0; 
	}

	*intpart = f & (( 0x80000000 >> ( e - 1 )) /*  e bits from mantissa */
	    + 0x000000ff);
	return  val .asfloat - (*intpart) .asfloat; /*  12.3 - 12.0  = 0.3  */
}


ff  frexp( f, exp ) /*  split f = fraction * 2^exp  */
reg ff f;  
reg int* exp;
{       
	reg long e;
	if( e = f & 0x7f )  e -= 64;
	*exp = e;       /*  e.g.  f = 800000 46         */
	return  f - e;  /*          = 800000 40  * 2^6  */
}


ff  ldexp( f, exp ) /*  f * 2^exp  */
reg ff f;  
reg int exp;
{       
	reg long e;
	e = (f & 0x7f) + exp;
	if( e < 0   || f == 0 )
		return  0;
	if( e > 127 )
		return  (f & 0x80) + 0xffffff7f; /*  +- maxfloat  */
	return  f + exp;
}
« March 2024 »
Su Mo Tu We Th Fr Sa
1 2
3 4 5 6 7 8 9
10 11 12 13 14 15 16
17 18 19 20 21 22 23
24 25 26 27 28 29 30
31
 

Powered by Plone CMS, the Open Source Content Management System

This site conforms to the following standards: