Changeset 992ffa6 in mainline for uspace/lib/math/generic
- Timestamp:
- 2015-09-04T06:40:20Z (10 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- 01cdd5a
- Parents:
- bae1e1f
- Location:
- uspace/lib/math/generic
- Files:
-
- 3 added
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/lib/math/generic/ceil.c
rbae1e1f r992ffa6 48 48 float64_u v; 49 49 float64_u r; 50 50 51 51 v.data = val; 52 52 t.data = trunc_float64(val); 53 53 54 54 if (val.parts.sign == 1 || v.val == t.val) { 55 55 r = t; … … 57 57 r.val = t.val + 1.0; 58 58 } 59 59 60 60 return r.data; 61 61 } -
uspace/lib/math/generic/floor.c
rbae1e1f r992ffa6 49 49 float64_u v; 50 50 float64_u r; 51 51 52 52 v.data = val; 53 53 t.data = trunc_float64(val); 54 54 55 55 if (val.parts.sign == 0 || v.val == t.val) { 56 56 r = t; … … 58 58 r.val = t.val - 1.0; 59 59 } 60 60 61 61 return r.data; 62 62 } -
uspace/lib/math/generic/trig.c
rbae1e1f r992ffa6 36 36 #include <trig.h> 37 37 38 #define TAYLOR_DEGREE 13 38 #define TAYLOR_DEGREE_32 13 39 #define TAYLOR_DEGREE_64 21 39 40 40 41 /** Precomputed values for factorial (starting from 1!) */ 41 static float64_t factorials[TAYLOR_DEGREE ] = {42 static float64_t factorials[TAYLOR_DEGREE_64] = { 42 43 1, 2, 6, 24, 120, 720, 5040, 40320, 362880, 3628800, 39916800, 43 479001600, 6227020800 44 479001600, 6227020800.0L, 87178291200.0L, 1307674368000.0L, 45 20922789888000.0L, 355687428096000.0L, 6402373705728000.0L, 46 121645100408832000.0L, 2432902008176640000.0L, 51090942171709440000.0L 44 47 }; 45 48 … … 61 64 float64_t nom = 1; 62 65 63 for (unsigned int i = 0; i < TAYLOR_DEGREE ; i++) {66 for (unsigned int i = 0; i < TAYLOR_DEGREE_64; i++) { 64 67 nom *= arg; 65 68 … … 90 93 float64_t nom = 1; 91 94 92 for (unsigned int i = 0; i < TAYLOR_DEGREE ; i++) {95 for (unsigned int i = 0; i < TAYLOR_DEGREE_64; i++) { 93 96 nom *= arg; 94 97 -
uspace/lib/math/generic/trunc.c
rbae1e1f r992ffa6 35 35 #include <mathtypes.h> 36 36 #include <trunc.h> 37 38 /** Truncate fractional part (round towards zero) 39 * 40 * Truncate the fractional part of IEEE 754 single 41 * precision floating point number by zeroing fraction 42 * bits, effectively rounding the number towards zero 43 * to the nearest whole number. 44 * 45 * If the argument is infinity or NaN, an exception 46 * should be indicated. This is not implemented yet. 47 * 48 * @param val Floating point number. 49 * 50 * @return Number rounded towards zero. 51 * 52 */ 53 float32 trunc_float32(float32 val) 54 { 55 int32_t exp = val.parts.exp - FLOAT32_BIAS; 56 57 if (exp < 0) { 58 /* -1 < val < 1 => result is +0 or -0 */ 59 val.parts.exp = 0; 60 val.parts.fraction = 0; 61 } else if (exp >= FLOAT32_FRACTION_SIZE) { 62 if (exp == 1024) { 63 /* val is +inf, -inf or NaN => trigger an exception */ 64 // FIXME TODO 65 } 66 67 /* All bits in val are relevant for the result */ 68 } else { 69 /* Truncate irrelevant fraction bits */ 70 val.parts.fraction &= ~(UINT32_C(0x007fffff) >> exp); 71 } 72 73 return val; 74 } 37 75 38 76 /** Truncate fractional part (round towards zero)
Note:
See TracChangeset
for help on using the changeset viewer.