Changeset c0c38c7c in mainline for uspace/lib/math
- Timestamp:
- 2015-03-14T21:36:44Z (10 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- 7f9d97f3
- Parents:
- 2c7fdaa
- Location:
- uspace/lib/math
- Files:
-
- 15 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/lib/math/arch/abs32le/include/libarch/math.h
r2c7fdaa rc0c38c7c 41 41 #include <trig.h> 42 42 43 static inline double fmod(double dividend, doubledivisor)43 static inline float64_t fmod(float64_t dividend, float64_t divisor) 44 44 { 45 return double_mod(dividend, divisor);45 return float64_mod(dividend, divisor); 46 46 } 47 47 48 static inline double trunc(doubleval)48 static inline float64_t trunc(float64_t val) 49 49 { 50 double_targ;50 float64_u arg; 51 51 arg.val = val; 52 52 53 double_tret;53 float64_u ret; 54 54 ret.data = trunc_float64(arg.data); 55 55 … … 57 57 } 58 58 59 static inline double sin(doubleval)59 static inline float64_t sin(float64_t val) 60 60 { 61 return double_sin(val);61 return float64_sin(val); 62 62 } 63 63 64 static inline double cos(doubleval)64 static inline float64_t cos(float64_t val) 65 65 { 66 return double_cos(val);66 return float64_cos(val); 67 67 } 68 68 -
uspace/lib/math/arch/amd64/include/libarch/math.h
r2c7fdaa rc0c38c7c 36 36 #define LIBMATH_amd64_MATH_H_ 37 37 38 #include <mathtypes.h> 38 39 #include <mod.h> 39 40 40 static inline double fmod(double dividend, doubledivisor)41 static inline float64_t fmod(float64_t dividend, float64_t divisor) 41 42 { 42 return double_mod(dividend, divisor);43 return float64_mod(dividend, divisor); 43 44 } 44 45 45 extern double sin(double);46 extern double cos(double);47 extern double trunc(double);46 extern float64_t sin(float64_t); 47 extern float64_t cos(float64_t); 48 extern float64_t trunc(float64_t); 48 49 49 50 #endif -
uspace/lib/math/arch/arm32/include/libarch/math.h
r2c7fdaa rc0c38c7c 41 41 #include <trig.h> 42 42 43 static inline double fmod(double dividend, doubledivisor)43 static inline float64_t fmod(float64_t dividend, float64_t divisor) 44 44 { 45 return double_mod(dividend, divisor);45 return float64_mod(dividend, divisor); 46 46 } 47 47 48 static inline double trunc(doubleval)48 static inline float64_t trunc(float64_t val) 49 49 { 50 double_targ;50 float64_u arg; 51 51 arg.val = val; 52 52 53 double_tret;53 float64_u ret; 54 54 ret.data = trunc_float64(arg.data); 55 55 … … 57 57 } 58 58 59 static inline double sin(doubleval)59 static inline float64_t sin(float64_t val) 60 60 { 61 return double_sin(val);61 return float64_sin(val); 62 62 } 63 63 64 static inline double cos(doubleval)64 static inline float64_t cos(float64_t val) 65 65 { 66 return double_cos(val);66 return float64_cos(val); 67 67 } 68 68 -
uspace/lib/math/arch/ia32/include/libarch/math.h
r2c7fdaa rc0c38c7c 36 36 #define LIBMATH_ia32_MATH_H_ 37 37 38 #include <mathtypes.h> 38 39 #include <mod.h> 39 40 40 static inline double fmod(double dividend, doubledivisor)41 static inline float64_t fmod(float64_t dividend, float64_t divisor) 41 42 { 42 return double_mod(dividend, divisor);43 return float64_mod(dividend, divisor); 43 44 } 44 45 45 extern double sin(double);46 extern double cos(double);47 extern double trunc(double);46 extern float64_t sin(float64_t); 47 extern float64_t cos(float64_t); 48 extern float64_t trunc(float64_t); 48 49 49 50 #endif -
uspace/lib/math/arch/ia64/include/libarch/math.h
r2c7fdaa rc0c38c7c 41 41 #include <trig.h> 42 42 43 static inline double fmod(double dividend, doubledivisor)43 static inline float64_t fmod(float64_t dividend, float64_t divisor) 44 44 { 45 return double_mod(dividend, divisor);45 return float64_mod(dividend, divisor); 46 46 } 47 47 48 static inline double trunc(doubleval)48 static inline float64_t trunc(float64_t val) 49 49 { 50 double_targ;50 float64_u arg; 51 51 arg.val = val; 52 52 53 double_tret;53 float64_u ret; 54 54 ret.data = trunc_float64(arg.data); 55 55 … … 57 57 } 58 58 59 static inline double sin(doubleval)59 static inline float64_t sin(float64_t val) 60 60 { 61 return double_sin(val);61 return float64_sin(val); 62 62 } 63 63 64 static inline double cos(doubleval)64 static inline float64_t cos(float64_t val) 65 65 { 66 return double_cos(val);66 return float64_cos(val); 67 67 } 68 68 -
uspace/lib/math/arch/mips32/include/libarch/math.h
r2c7fdaa rc0c38c7c 41 41 #include <trig.h> 42 42 43 static inline double fmod(double dividend, doubledivisor)43 static inline float64_t fmod(float64_t dividend, float64_t divisor) 44 44 { 45 return double_mod(dividend, divisor);45 return float64_mod(dividend, divisor); 46 46 } 47 47 48 static inline double trunc(doubleval)48 static inline float64_t trunc(float64_t val) 49 49 { 50 double_targ;50 float64_u arg; 51 51 arg.val = val; 52 52 53 double_tret;53 float64_u ret; 54 54 ret.data = trunc_float64(arg.data); 55 55 … … 57 57 } 58 58 59 static inline double sin(doubleval)59 static inline float64_t sin(float64_t val) 60 60 { 61 return double_sin(val);61 return float64_sin(val); 62 62 } 63 63 64 static inline double cos(doubleval)64 static inline float64_t cos(float64_t val) 65 65 { 66 return double_cos(val);66 return float64_cos(val); 67 67 } 68 68 -
uspace/lib/math/arch/mips32eb/include/libarch/math.h
r2c7fdaa rc0c38c7c 41 41 #include <trig.h> 42 42 43 static inline double fmod(double dividend, doubledivisor)43 static inline float64_t fmod(float64_t dividend, float64_t divisor) 44 44 { 45 return double_mod(dividend, divisor);45 return float64_mod(dividend, divisor); 46 46 } 47 47 48 static inline double trunc(doubleval)48 static inline float64_t trunc(float64_t val) 49 49 { 50 double_targ;50 float64_u arg; 51 51 arg.val = val; 52 52 53 double_tret;53 float64_u ret; 54 54 ret.data = trunc_float64(arg.data); 55 55 … … 57 57 } 58 58 59 static inline double sin(doubleval)59 static inline float64_t sin(float64_t val) 60 60 { 61 return double_sin(val);61 return float64_sin(val); 62 62 } 63 63 64 static inline double cos(doubleval)64 static inline float64_t cos(float64_t val) 65 65 { 66 return double_cos(val);66 return float64_cos(val); 67 67 } 68 68 -
uspace/lib/math/arch/ppc32/include/libarch/math.h
r2c7fdaa rc0c38c7c 41 41 #include <trig.h> 42 42 43 static inline double fmod(double dividend, doubledivisor)43 static inline float64_t fmod(float64_t dividend, float64_t divisor) 44 44 { 45 return double_mod(dividend, divisor);45 return float64_mod(dividend, divisor); 46 46 } 47 47 48 48 static inline double trunc(double val) 49 49 { 50 double_targ;50 float64_u arg; 51 51 arg.val = val; 52 52 53 double_tret;53 float64_u ret; 54 54 ret.data = trunc_float64(arg.data); 55 55 … … 57 57 } 58 58 59 static inline double sin(doubleval)59 static inline float64_t sin(float64_t val) 60 60 { 61 return double_sin(val);61 return float64_sin(val); 62 62 } 63 63 64 static inline double cos(doubleval)64 static inline float64_t cos(float64_t val) 65 65 { 66 return double_cos(val);66 return float64_cos(val); 67 67 } 68 68 -
uspace/lib/math/arch/sparc32/include/libarch/math.h
r2c7fdaa rc0c38c7c 41 41 #include <trig.h> 42 42 43 static inline double fmod(double dividend, doubledivisor)43 static inline float64_t fmod(float64_t dividend, float64_t divisor) 44 44 { 45 return double_mod(dividend, divisor);45 return float64_mod(dividend, divisor); 46 46 } 47 47 48 static inline double trunc(doubleval)48 static inline float64_t trunc(float64_t val) 49 49 { 50 double_targ;50 float64_u arg; 51 51 arg.val = val; 52 52 53 double_tret;53 float64_u ret; 54 54 ret.data = trunc_float64(arg.data); 55 55 … … 57 57 } 58 58 59 static inline double sin(doubleval)59 static inline float64_t sin(float64_t val) 60 60 { 61 return double_sin(val);61 return float64_sin(val); 62 62 } 63 63 64 static inline double cos(doubleval)64 static inline float64_t cos(float64_t val) 65 65 { 66 return double_cos(val);66 return float64_cos(val); 67 67 } 68 68 -
uspace/lib/math/arch/sparc64/include/libarch/math.h
r2c7fdaa rc0c38c7c 41 41 #include <trig.h> 42 42 43 static inline double fmod(double dividend, doubledivisor)43 static inline float64_t fmod(float64_t dividend, float64_t divisor) 44 44 { 45 return double_mod(dividend, divisor);45 return float64_mod(dividend, divisor); 46 46 } 47 47 48 static inline double trunc(doubleval)48 static inline float64_t trunc(float64_t val) 49 49 { 50 double_targ;50 float64_u arg; 51 51 arg.val = val; 52 52 53 double_tret;53 float64_u ret; 54 54 ret.data = trunc_float64(arg.data); 55 55 … … 57 57 } 58 58 59 static inline double sin(doubleval)59 static inline float64_t sin(float64_t val) 60 60 { 61 return double_sin(val);61 return float64_sin(val); 62 62 } 63 63 64 static inline double cos(doubleval)64 static inline float64_t cos(float64_t val) 65 65 { 66 return double_cos(val);66 return float64_cos(val); 67 67 } 68 68 -
uspace/lib/math/generic/mod.c
r2c7fdaa rc0c38c7c 52 52 * 53 53 */ 54 double double_mod(double dividend, doubledivisor)54 float64_t float64_mod(float64_t dividend, float64_t divisor) 55 55 { 56 56 // FIXME: replace with exact arithmetics 57 57 58 doublequotient = trunc(dividend / divisor);58 float64_t quotient = trunc(dividend / divisor); 59 59 60 60 return (dividend - quotient * divisor); -
uspace/lib/math/generic/trig.c
r2c7fdaa rc0c38c7c 39 39 40 40 /** Precomputed values for factorial (starting from 1!) */ 41 static doublefactorials[TAYLOR_DEGREE] = {41 static float64_t factorials[TAYLOR_DEGREE] = { 42 42 1, 2, 6, 24, 120, 720, 5040, 40320, 362880, 3628800, 39916800, 43 43 479001600, 6227020800 … … 56 56 * 57 57 */ 58 static double taylor_sin(doublearg)59 { 60 doubleret = 0;61 doublenom = 1;58 static float64_t taylor_sin(float64_t arg) 59 { 60 float64_t ret = 0; 61 float64_t nom = 1; 62 62 63 63 for (unsigned int i = 0; i < TAYLOR_DEGREE; i++) { … … 85 85 * 86 86 */ 87 static double taylor_cos(doublearg)88 { 89 doubleret = 1;90 doublenom = 1;87 static float64_t taylor_cos(float64_t arg) 88 { 89 float64_t ret = 1; 90 float64_t nom = 1; 91 91 92 92 for (unsigned int i = 0; i < TAYLOR_DEGREE; i++) { … … 114 114 * 115 115 */ 116 static double base_sin(doublearg)116 static float64_t base_sin(float64_t arg) 117 117 { 118 118 unsigned int period = arg / (M_PI / 4); … … 147 147 * 148 148 */ 149 static double base_cos(doublearg)149 static float64_t base_cos(float64_t arg) 150 150 { 151 151 unsigned int period = arg / (M_PI / 4); … … 156 156 case 1: 157 157 case 2: 158 return taylor_sin(arg - M_PI / 2);158 return -taylor_sin(arg - M_PI / 2); 159 159 case 3: 160 160 case 4: … … 162 162 case 5: 163 163 case 6: 164 return -taylor_sin(arg - 3 * M_PI / 2);164 return taylor_sin(arg - 3 * M_PI / 2); 165 165 default: 166 166 return taylor_cos(arg - 2 * M_PI); … … 177 177 * 178 178 */ 179 double double_sin(doublearg)180 { 181 doublebase_arg = fmod(arg, 2 * M_PI);179 float64_t float64_sin(float64_t arg) 180 { 181 float64_t base_arg = fmod(arg, 2 * M_PI); 182 182 183 183 if (base_arg < 0) … … 196 196 * 197 197 */ 198 double double_cos(doublearg)199 { 200 doublebase_arg = fmod(arg, 2 * M_PI);198 float64_t float64_cos(float64_t arg) 199 { 200 float64_t base_arg = fmod(arg, 2 * M_PI); 201 201 202 202 if (base_arg < 0) -
uspace/lib/math/include/mathtypes.h
r2c7fdaa rc0c38c7c 191 191 #endif 192 192 193 typedef union { 194 float val; 195 193 196 194 #if defined(FLOAT_SIZE_32) 195 196 #ifndef float32_t 197 #define float32_t float 198 #endif 199 200 #elif defined(FLOAT_SIZE_64) 201 202 #ifndef float64_t 203 #define float64_t float 204 #endif 205 206 #elif defined(FLOAT_SIZE_96) 207 208 #ifndef float96_t 209 #define float96_t float 210 #endif 211 212 #elif defined(FLOAT_SIZE_128) 213 214 #ifndef float128_t 215 #define float128_t float 216 #endif 217 218 #endif 219 220 221 #if defined(DOUBLE_SIZE_32) 222 223 #ifndef float32_t 224 #define float32_t double 225 #endif 226 227 #elif defined(DOUBLE_SIZE_64) 228 229 #ifndef float64_t 230 #define float64_t double 231 #endif 232 233 #elif defined(DOUBLE_SIZE_96) 234 235 #ifndef float96_t 236 #define float96_t double 237 #endif 238 239 #elif defined(DOUBLE_SIZE_128) 240 241 #ifndef float128_t 242 #define float128_t double 243 #endif 244 245 #endif 246 247 248 #if defined(LONG_DOUBLE_SIZE_32) 249 250 #ifndef float32_t 251 #define float32_t long double 252 #endif 253 254 #elif defined(LONG_DOUBLE_SIZE_64) 255 256 #ifndef float64_t 257 #define float64_t long double 258 #endif 259 260 #elif defined(LONG_DOUBLE_SIZE_96) 261 262 #ifndef float96_t 263 #define float96_t long double 264 #endif 265 266 #elif defined(LONG_DOUBLE_SIZE_128) 267 268 #ifndef float128_t 269 #define float128_t long double 270 #endif 271 272 #endif 273 274 275 #ifdef float32_t 276 277 typedef union { 278 float32_t val; 197 279 float32 data; 198 #elif defined(FLOAT_SIZE_64) 280 } float32_u; 281 282 #endif 283 284 #ifdef float64_t 285 286 typedef union { 287 float64_t val; 199 288 float64 data; 200 #elif defined(FLOAT_SIZE_96) 289 } float64_u; 290 291 #endif 292 293 #ifdef float96_t 294 295 typedef union { 296 float96_t val; 201 297 float96 data; 202 #elif defined(FLOAT_SIZE_128) 298 } float96_u; 299 300 #endif 301 302 #ifdef float128_t 303 304 typedef union { 305 float128_t val; 203 306 float128 data; 204 #else 205 #error Unsupported float size 206 #endif 207 } float_t; 208 209 typedef union { 210 double val; 211 212 #if defined(DOUBLE_SIZE_32) 213 float32 data; 214 #elif defined(DOUBLE_SIZE_64) 215 float64 data; 216 #elif defined(DOUBLE_SIZE_96) 217 float96 data; 218 #elif defined(DOUBLE_SIZE_128) 219 float128 data; 220 #else 221 #error Unsupported double size 222 #endif 223 } double_t; 224 225 typedef union { 226 long double val; 227 228 #if defined(LONG_DOUBLE_SIZE_32) 229 float32 data; 230 #elif defined(LONG_DOUBLE_SIZE_64) 231 float64 data; 232 #elif defined(LONG_DOUBLE_SIZE_96) 233 float96 data; 234 #elif defined(LONG_DOUBLE_SIZE_128) 235 float128 data; 236 #else 237 #error Unsupported long double size 238 #endif 239 } long_double_t; 307 } float128_u; 308 309 #endif 240 310 241 311 #endif -
uspace/lib/math/include/mod.h
r2c7fdaa rc0c38c7c 36 36 #define LIBMATH_MOD_H_ 37 37 38 extern double double_mod(double, double);38 extern float64_t float64_mod(float64_t, float64_t); 39 39 40 40 #endif -
uspace/lib/math/include/trig.h
r2c7fdaa rc0c38c7c 36 36 #define LIBMATH_TRIG_H_ 37 37 38 extern double double_sin(double);39 extern double double_cos(double);38 extern float64_t float64_sin(float64_t); 39 extern float64_t float64_cos(float64_t); 40 40 41 41 #endif
Note:
See TracChangeset
for help on using the changeset viewer.