Files
tp/include/MSL_C/MSL_Common/Src/float.h
T
TakaRikka 589cc12296 some MSL_C work (#192)
* wip

* bunch of MSL_C files

thanks to pikmin2 decomp for their work

* format / asm

* progress

* fix

* fix remove-asm to work with C files

* init / start
2022-04-24 13:02:50 +02:00

50 lines
1.0 KiB
C

#ifndef MSL_COMMON_SRC_FLOAT_H
#define MSL_COMMON_SRC_FLOAT_H
#include "dolphin/types.h"
#define FP_SNAN 0
#define FP_QNAN 1
#define FP_INFINITE 2
#define FP_ZERO 3
#define FP_NORMAL 4
#define FP_SUBNORMAL 5
#define FP_NAN FP_QNAN
#define fpclassify(x) ((sizeof(x) == sizeof(float)) ? __fpclassifyf(x) : __fpclassifyd(x))
#define signbit(x) ((sizeof(x) == sizeof(float)) ? __signbitf(x) : __signbitd(x))
#define isfinite(x) ((fpclassify(x) > 2))
#define __signbitf(x) ((*(u8*)&(x)) & 0x80)
// TODO: OK?
#define __signbitd(x) ((*(u8*)&(x)) & 0x80)
inline int __fpclassifyf(float __value) {
u32 integer = *(u32*)&__value;
switch (integer & 0x7f800000) {
case 0x7f800000:
if ((integer & 0x7fffff) != 0) {
return FP_QNAN;
}
return FP_INFINITE;
case 0:
if ((integer & 0x7fffff) != 0) {
return FP_SUBNORMAL;
}
return FP_ZERO;
}
return FP_NORMAL;
}
inline int __fpclassifyd(double __value) {
// TODO:
return FP_INFINITE;
}
#endif /* MSL_COMMON_SRC_FLOAT_H */