add FLT_MAX, FLT_EPSILON, NAN, and HUGE_VALF to MSL_C headers (#316)

This commit is contained in:
Jcw87
2023-04-21 02:01:46 -07:00
committed by GitHub
parent 0629e60eab
commit 6f30fa4d2a
20 changed files with 65 additions and 50 deletions
+5
View File
@@ -21,6 +21,11 @@
// TODO: OK?
#define __signbitd(x) ((*(unsigned char*)&(x)) & 0x80)
extern unsigned long __float_nan[];
extern unsigned long __float_huge[];
extern unsigned long __float_max[];
extern unsigned long __float_epsilon[];
inline int __fpclassifyf(float __value) {
unsigned long integer = *(unsigned long*)&__value;
+10
View File
@@ -0,0 +1,10 @@
#ifndef MSL_FLOAT_H_
#define MSL_FLOAT_H_
#include "MSL_C/MSL_Common/Src/float.h"
#define FLT_MAX (*(float*) __float_max)
#define FLT_EPSILON (*(float*) __float_epsilon)
#endif
+5 -6
View File
@@ -3,6 +3,9 @@
#include "MSL_C/MSL_Common/Src/float.h"
#define NAN (*(float*) __float_nan)
#define HUGE_VALF (*(float*) __float_huge)
#define M_PI 3.14159265358979323846f
#define DEG_TO_RAD(degrees) (degrees * (M_PI / 180.0f))
@@ -50,10 +53,6 @@ double sqrt(double);
double tan(double);
float tanf(float);
extern float __float_nan[4];
extern float __float_epsilon[4];
extern float __float_max[4];
inline double sqrt_step(double tmpd, float mag) {
return tmpd * 0.5 * (3.0 - mag * (tmpd * tmpd));
}
@@ -66,9 +65,9 @@ inline float sqrtf(float mag) {
tmpd = sqrt_step(tmpd, mag);
return mag * tmpd;
} else if (mag < 0.0) {
return __float_nan[0];
return NAN;
} else if (fpclassify(mag) == 1) {
return __float_nan[0];
return NAN;
} else {
return mag;
}
-2
View File
@@ -80,10 +80,8 @@
#define _HUGE_ENUF 1e+300
#define INFINITY ((float)(_HUGE_ENUF * _HUGE_ENUF))
#define HUGE_VAL ((double)INFINITY)
#define HUGE_VALF ((float)INFINITY)
#define HUGE_VALL ((long double)INFINITY)
#define FLOAT_INF HUGE_VALF
#define DOUBLE_INF HUGE_VAL
#pragma section ".dead"