summaryrefslogblamecommitdiff
path: root/src/math/rintl.c
blob: 267250737f0a8e3b3924ee7bb662bbce2bbf6a9e (plain) (tree)
1
2
3
4
5
6
7
8
9







                                                                            
                       
                    
                          
                     
      

                                













                                        

      
#include "libm.h"

#if LDBL_MANT_DIG == 53 && LDBL_MAX_EXP == 1024
long double rintl(long double x)
{
	return rint(x);
}
#elif (LDBL_MANT_DIG == 64 || LDBL_MANT_DIG == 113) && LDBL_MAX_EXP == 16384
#if LDBL_MANT_DIG == 64
#define TOINT 0x1p63
#elif LDBL_MANT_DIG == 113
#define TOINT 0x1p112
#endif
long double rintl(long double x)
{
	union ldshape u = {x};
	int e = u.i.se & 0x7fff;
	int s = u.i.se >> 15;
	long double y;

	if (e >= 0x3fff+LDBL_MANT_DIG-1)
		return x;
	if (s)
		y = x - TOINT + TOINT;
	else
		y = x + TOINT - TOINT;
	if (y == 0)
		return 0*x;
	return y;
}
#endif