mirror of
https://github.com/UpsilonNumworks/Upsilon.git
synced 2026-01-19 00:37:25 +01:00
[liba] Add isinff and isnanf
Change-Id: I7141c6aef7dc8fed3538f157f9c1fcec76d951d1
This commit is contained in:
@@ -2,7 +2,20 @@ SFLAGS += -Iliba/include
|
||||
|
||||
liba/src/external/sqlite/mem5.o: CFLAGS += -w
|
||||
|
||||
objs += $(addprefix liba/src/, assert.o errno.o malloc.o memcpy.o memset.o strcmp.o strlcpy.o strlen.o external/sqlite/mem5.o)
|
||||
objs += $(addprefix liba/src/, \
|
||||
assert.o \
|
||||
errno.o \
|
||||
ieee754.o \
|
||||
isnanf.o \
|
||||
isinff.o \
|
||||
malloc.o \
|
||||
memcpy.o \
|
||||
memset.o \
|
||||
strcmp.o \
|
||||
strlcpy.o \
|
||||
strlen.o \
|
||||
external/sqlite/mem5.o \
|
||||
)
|
||||
|
||||
objs += $(addprefix liba/src/external/openbsd/, \
|
||||
e_log10f.o \
|
||||
@@ -25,7 +38,11 @@ objs += $(addprefix liba/src/external/openbsd/, \
|
||||
|
||||
liba/src/external/openbsd/%.o: CFLAGS += -Iliba/src/external/openbsd/include -Wno-parentheses
|
||||
|
||||
tests += $(addprefix liba/test/, stdint.c strlcpy.c)
|
||||
tests += $(addprefix liba/test/, \
|
||||
ieee754.c \
|
||||
stdint.c \
|
||||
strlcpy.c \
|
||||
)
|
||||
|
||||
# The use of aeabi-rt could be made conditional to an AEABI target.
|
||||
# In practice we're always using liba on such a target.
|
||||
|
||||
@@ -5,6 +5,9 @@
|
||||
|
||||
LIBA_BEGIN_DECLS
|
||||
|
||||
int isinff(float x);
|
||||
int isnanf(float x);
|
||||
|
||||
float copysignf(float x, float y);
|
||||
float cosf(float x);
|
||||
float fabsf(float x);
|
||||
|
||||
9
liba/include/private/ieee754.h
Normal file
9
liba/include/private/ieee754.h
Normal file
@@ -0,0 +1,9 @@
|
||||
#ifndef LIBA_IEEE754_H
|
||||
#define LIBA_IEEE754_H
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
uint32_t ieee754man(float x);
|
||||
uint8_t ieee754exp(float x);
|
||||
|
||||
#endif
|
||||
19
liba/src/ieee754.c
Normal file
19
liba/src/ieee754.c
Normal file
@@ -0,0 +1,19 @@
|
||||
#include <private/ieee754.h>
|
||||
|
||||
uint32_t ieee754man(float x) {
|
||||
union {
|
||||
float f;
|
||||
uint32_t i;
|
||||
} u;
|
||||
u.f = x;
|
||||
return (u.i & ((1<<23)-1));
|
||||
}
|
||||
|
||||
uint8_t ieee754exp(float x) {
|
||||
union {
|
||||
float f;
|
||||
uint32_t i;
|
||||
} u;
|
||||
u.f = x;
|
||||
return (u.i >> 23) & 0xFF;
|
||||
}
|
||||
6
liba/src/isinff.c
Normal file
6
liba/src/isinff.c
Normal file
@@ -0,0 +1,6 @@
|
||||
#include <math.h>
|
||||
#include <private/ieee754.h>
|
||||
|
||||
int isinff(float x) {
|
||||
return (ieee754exp(x) == 0xFF && ieee754man(x) == 0);
|
||||
}
|
||||
6
liba/src/isnanf.c
Normal file
6
liba/src/isnanf.c
Normal file
@@ -0,0 +1,6 @@
|
||||
#include <math.h>
|
||||
#include <private/ieee754.h>
|
||||
|
||||
int isnanf(float x) {
|
||||
return (ieee754exp(x) == 0xFF && ieee754man(x) != 0);
|
||||
}
|
||||
12
liba/test/ieee754.c
Normal file
12
liba/test/ieee754.c
Normal file
@@ -0,0 +1,12 @@
|
||||
#include <quiz.h>
|
||||
#include <assert.h>
|
||||
#include <private/ieee754.h>
|
||||
|
||||
QUIZ_CASE(liba_ieee754) {
|
||||
assert(ieee754man(123.456f) == 7793017);
|
||||
assert(ieee754exp(123.456f) == 133);
|
||||
assert(ieee754man(555.555f) == 713605);
|
||||
assert(ieee754exp(555.555f) == 136);
|
||||
assert(ieee754man(0.007f) == 6643778);
|
||||
assert(ieee754exp(0.007f) == 119);
|
||||
}
|
||||
Reference in New Issue
Block a user