Changeset 516e780 in mainline for uspace/lib/math/generic/__fcompare.c
- Timestamp:
- 2018-08-31T11:55:41Z (6 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- fa86fff
- Parents:
- 7f7d642
- git-author:
- Jiří Zárevúcky <zarevucky.jiri@…> (2018-08-31 11:55:41)
- git-committer:
- GitHub <noreply@…> (2018-08-31 11:55:41)
- File:
-
- 1 moved
Legend:
- Unmodified
- Added
- Removed
-
uspace/lib/math/generic/__fcompare.c
r7f7d642 r516e780 1 1 /* 2 * Copyright (c) 201 5 Jiri Svoboda2 * Copyright (c) 2018 CZ.NIC, z.s.p.o. 3 3 * All rights reserved. 4 4 * … … 27 27 */ 28 28 29 /** @addtogroup libmath 30 * @{ 29 #include <math.h> 30 #include <stdarg.h> 31 32 /** 33 * Fallback symbol used when code including <math.h> is compiled with something 34 * other than GCC or Clang. The function itself must be built with GCC or Clang. 31 35 */ 32 /** @file 33 */ 36 int __fcompare(size_t sz1, size_t sz2, ...) 37 { 38 va_list ap; 39 va_start(ap, sz2); 34 40 35 #include <ceil.h> 36 #include <math.h> 37 #include <mathtypes.h> 41 long double val1; 42 long double val2; 38 43 39 /** Ceiling (round towards positive infinity, 32-bit floating point) 40 * 41 * @param val Floating point number. 42 * 43 * @return Number rounded towards positive infinity. 44 */ 45 float32_t float32_ceil(float32_t val) 46 { 47 float32_u t; 48 float32_u v; 49 float32_u r; 50 51 v.val = val; 52 t.val = trunc_f32(val); 53 54 if (v.data.parts.sign == 1 || val == t.val) { 55 r = t; 56 } else { 57 r.val = t.val + 1.0; 44 switch (sz1) { 45 case 4: 46 val1 = (long double) va_arg(ap, double); 47 break; 48 case 8: 49 val1 = (long double) va_arg(ap, double); 50 break; 51 default: 52 val1 = va_arg(ap, long double); 53 break; 58 54 } 59 55 60 return r.val; 56 switch (sz2) { 57 case 4: 58 val2 = (long double) va_arg(ap, double); 59 break; 60 case 8: 61 val2 = (long double) va_arg(ap, double); 62 break; 63 default: 64 val2 = va_arg(ap, long double); 65 break; 66 } 67 68 va_end(ap); 69 70 if (isgreaterequal(val1, val2)) { 71 if (isgreater(val1, val2)) 72 return __FCOMPARE_GREATER; 73 else 74 return __FCOMPARE_EQUAL; 75 } else { 76 if (isless(val1, val2)) 77 return __FCOMPARE_LESS; 78 else 79 return 0; 80 } 61 81 } 62 82 63 /** Ceiling (round towards positive infinity, 64-bit floating point)64 *65 * @param val Floating point number.66 *67 * @return Number rounded towards positive infinity.68 */69 float64_t float64_ceil(float64_t val)70 {71 float64_u t;72 float64_u v;73 float64_u r;74 75 v.val = val;76 t.val = trunc_f64(val);77 78 if (v.data.parts.sign == 1 || val == t.val) {79 r = t;80 } else {81 r.val = t.val + 1.0;82 }83 84 return r.val;85 }86 87 /** @}88 */
Note:
See TracChangeset
for help on using the changeset viewer.