mirror of
https://github.com/UpsilonNumworks/Upsilon.git
synced 2026-03-18 21:30:38 +01:00
[Poincare/IEEE754] Changed methods to use std function
Implemented std::nextafter to replace hand made one. Methods next and previous are no longer making the difference between -0 and +0 Change-Id: I42e1a073623b70656d9df954694803840cf3088c
This commit is contained in:
committed by
Émilie Feral
parent
338968a493
commit
1995781a9f
@@ -70,6 +70,8 @@ liba_src += $(addprefix liba/src/external/openbsd/, \
|
||||
s_logbf.c \
|
||||
s_modf.c \
|
||||
s_modff.c \
|
||||
s_nextafter.c \
|
||||
s_nextafterf.c \
|
||||
s_rint.c \
|
||||
s_roundf.c \
|
||||
s_scalbnf.c \
|
||||
|
||||
@@ -70,6 +70,7 @@ float log10f(float x);
|
||||
float logf(float x);
|
||||
float modff(float x, float *iptr);
|
||||
float nearbyintf(float x);
|
||||
float nextafterf(float from, float to);
|
||||
float powf(float x, float y);
|
||||
float roundf(float x);
|
||||
float scalbnf(float x, int exp);
|
||||
@@ -110,6 +111,7 @@ double log2(double x);
|
||||
double logb(double x);
|
||||
double modf(double x, double *iptr);
|
||||
double nearbyint(double x);
|
||||
double nextafter(double from, double to);
|
||||
double pow(double x, double y);
|
||||
double rint(double x);
|
||||
double round(double x);
|
||||
@@ -156,6 +158,7 @@ extern int signgam;
|
||||
#define modff(x, iptr) __builtin_modff(x, iptr)
|
||||
#define nanf(tagp) __builtin_nanf(tagp)
|
||||
#define nearbyintf(x) __builtin_nearbyintf(x)
|
||||
#define nextafterf(from, to) __builtin_nextafterf(from, to)
|
||||
#define powf(x, y) __builtin_powf(x, y)
|
||||
#define roundf(x) __builtin_roundf(x)
|
||||
#define scalbnf(x, exp) __builtin_scalbnf(x, exp)
|
||||
@@ -196,6 +199,7 @@ extern int signgam;
|
||||
#define modf(x, iptr) __builtin_modf(x, iptr)
|
||||
#define nan(tagp) __builtin_nan(tagp)
|
||||
#define nearbyint(x) __builtin_nearbyint(x)
|
||||
#define nextafter(from, to) __builtin_nextafter(from, to)
|
||||
#define pow(x, y) __builtin_pow(x, y)
|
||||
#define rint(x) __builtin_rint(x)
|
||||
#define round(x) __builtin_round(x)
|
||||
|
||||
71
liba/src/external/openbsd/s_nextafter.c
vendored
Normal file
71
liba/src/external/openbsd/s_nextafter.c
vendored
Normal file
@@ -0,0 +1,71 @@
|
||||
/* @(#)s_nextafter.c 5.1 93/09/24 */
|
||||
/*
|
||||
* ====================================================
|
||||
* Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
|
||||
*
|
||||
* Developed at SunPro, a Sun Microsystems, Inc. business.
|
||||
* Permission to use, copy, modify, and distribute this
|
||||
* software is freely granted, provided that this notice
|
||||
* is preserved.
|
||||
* ====================================================
|
||||
*/
|
||||
|
||||
/* IEEE functions
|
||||
* nextafter(x,y)
|
||||
* return the next machine floating-point number of x in the
|
||||
* direction toward y.
|
||||
* Special cases:
|
||||
*/
|
||||
|
||||
#include "math.h"
|
||||
#include "math_private.h"
|
||||
|
||||
double
|
||||
nextafter(double x, double y)
|
||||
{
|
||||
int32_t hx,hy,ix,iy;
|
||||
u_int32_t lx,ly;
|
||||
|
||||
EXTRACT_WORDS(hx,lx,x);
|
||||
EXTRACT_WORDS(hy,ly,y);
|
||||
ix = hx&0x7fffffff; /* |x| */
|
||||
iy = hy&0x7fffffff; /* |y| */
|
||||
|
||||
if(((ix>=0x7ff00000)&&((ix-0x7ff00000)|lx)!=0) || /* x is nan */
|
||||
((iy>=0x7ff00000)&&((iy-0x7ff00000)|ly)!=0)) /* y is nan */
|
||||
return x+y;
|
||||
if(x==y) return x; /* x=y, return x */
|
||||
if((ix|lx)==0) { /* x == 0 */
|
||||
INSERT_WORDS(x,hy&0x80000000,1); /* return +-minsubnormal */
|
||||
y = x*x;
|
||||
if(y==x) return y; else return x; /* raise underflow flag */
|
||||
}
|
||||
if(hx>=0) { /* x > 0 */
|
||||
if(hx>hy||((hx==hy)&&(lx>ly))) { /* x > y, x -= ulp */
|
||||
if(lx==0) hx -= 1;
|
||||
lx -= 1;
|
||||
} else { /* x < y, x += ulp */
|
||||
lx += 1;
|
||||
if(lx==0) hx += 1;
|
||||
}
|
||||
} else { /* x < 0 */
|
||||
if(hy>=0||hx>hy||((hx==hy)&&(lx>ly))){/* x < y, x -= ulp */
|
||||
if(lx==0) hx -= 1;
|
||||
lx -= 1;
|
||||
} else { /* x > y, x += ulp */
|
||||
lx += 1;
|
||||
if(lx==0) hx += 1;
|
||||
}
|
||||
}
|
||||
hy = hx&0x7ff00000;
|
||||
if(hy>=0x7ff00000) return x+x; /* overflow */
|
||||
if(hy<0x00100000) { /* underflow */
|
||||
y = x*x;
|
||||
if(y!=x) { /* raise underflow flag */
|
||||
INSERT_WORDS(y,hx,lx);
|
||||
return y;
|
||||
}
|
||||
}
|
||||
INSERT_WORDS(x,hx,lx);
|
||||
return x;
|
||||
}
|
||||
62
liba/src/external/openbsd/s_nextafterf.c
vendored
Normal file
62
liba/src/external/openbsd/s_nextafterf.c
vendored
Normal file
@@ -0,0 +1,62 @@
|
||||
/* s_nextafterf.c -- float version of s_nextafter.c.
|
||||
* Conversion to float by Ian Lance Taylor, Cygnus Support, ian@cygnus.com.
|
||||
*/
|
||||
|
||||
/*
|
||||
* ====================================================
|
||||
* Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
|
||||
*
|
||||
* Developed at SunPro, a Sun Microsystems, Inc. business.
|
||||
* Permission to use, copy, modify, and distribute this
|
||||
* software is freely granted, provided that this notice
|
||||
* is preserved.
|
||||
* ====================================================
|
||||
*/
|
||||
|
||||
#include "math.h"
|
||||
#include "math_private.h"
|
||||
|
||||
float
|
||||
nextafterf(float x, float y)
|
||||
{
|
||||
int32_t hx,hy,ix,iy;
|
||||
|
||||
GET_FLOAT_WORD(hx,x);
|
||||
GET_FLOAT_WORD(hy,y);
|
||||
ix = hx&0x7fffffff; /* |x| */
|
||||
iy = hy&0x7fffffff; /* |y| */
|
||||
|
||||
if((ix>0x7f800000) || /* x is nan */
|
||||
(iy>0x7f800000)) /* y is nan */
|
||||
return x+y;
|
||||
if(x==y) return x; /* x=y, return x */
|
||||
if(ix==0) { /* x == 0 */
|
||||
SET_FLOAT_WORD(x,(hy&0x80000000)|1);/* return +-minsubnormal */
|
||||
y = x*x;
|
||||
if(y==x) return y; else return x; /* raise underflow flag */
|
||||
}
|
||||
if(hx>=0) { /* x > 0 */
|
||||
if(hx>hy) { /* x > y, x -= ulp */
|
||||
hx -= 1;
|
||||
} else { /* x < y, x += ulp */
|
||||
hx += 1;
|
||||
}
|
||||
} else { /* x < 0 */
|
||||
if(hy>=0||hx>hy){ /* x < y, x -= ulp */
|
||||
hx -= 1;
|
||||
} else { /* x > y, x += ulp */
|
||||
hx += 1;
|
||||
}
|
||||
}
|
||||
hy = hx&0x7f800000;
|
||||
if(hy>=0x7f800000) return x+x; /* overflow */
|
||||
if(hy<0x00800000) { /* underflow */
|
||||
y = x*x;
|
||||
if(y!=x) { /* raise underflow flag */
|
||||
SET_FLOAT_WORD(y,hx);
|
||||
return y;
|
||||
}
|
||||
}
|
||||
SET_FLOAT_WORD(x,hx);
|
||||
return x;
|
||||
}
|
||||
Reference in New Issue
Block a user