diff options
author | Damien George <damien.p.george@gmail.com> | 2014-08-29 22:42:26 +0100 |
---|---|---|
committer | Damien George <damien.p.george@gmail.com> | 2014-08-29 22:42:26 +0100 |
commit | 8707ea34218a0aae071d4fb8d25e23273c828ea1 (patch) | |
tree | ac3740094df4d6620ef1e6f73afaa46c1841ca50 /lib/libm/libm.h | |
parent | 17ae2395c24544a8263ecf1e88572a571325a1ec (diff) |
lib: Add lib and libm, moving current files from stmhal.
Top-level lib directory is for standard C libraries that we want to
provide our own versions of (for efficiency and stand-alone reasons).
It currently has libm in it for math functions.
Also add atanf and atan2f, which addresses issue #837.
Diffstat (limited to 'lib/libm/libm.h')
-rw-r--r-- | lib/libm/libm.h | 52 |
1 files changed, 52 insertions, 0 deletions
diff --git a/lib/libm/libm.h b/lib/libm/libm.h new file mode 100644 index 000000000..c87c55821 --- /dev/null +++ b/lib/libm/libm.h @@ -0,0 +1,52 @@ +/*****************************************************************************/ +/*****************************************************************************/ +// portions extracted from musl-0.9.15 libm.h +/*****************************************************************************/ +/*****************************************************************************/ + +/* origin: FreeBSD /usr/src/lib/msun/src/math_private.h */ +/* + * ==================================================== + * 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 <stdint.h> +#include <math.h> + +#define FORCE_EVAL(x) do { \ + if (sizeof(x) == sizeof(float)) { \ + volatile float __x; \ + __x = (x); \ + (void)__x; \ + } else if (sizeof(x) == sizeof(double)) { \ + volatile double __x; \ + __x = (x); \ + (void)__x; \ + } else { \ + volatile long double __x; \ + __x = (x); \ + (void)__x; \ + } \ +} while(0) + +/* Get a 32 bit int from a float. */ +#define GET_FLOAT_WORD(w,d) \ +do { \ + union {float f; uint32_t i;} __u; \ + __u.f = (d); \ + (w) = __u.i; \ +} while (0) + +/* Set a float from a 32 bit int. */ +#define SET_FLOAT_WORD(d,w) \ +do { \ + union {float f; uint32_t i;} __u; \ + __u.i = (w); \ + (d) = __u.f; \ +} while (0) |