Changeset 8e7c9fe in mainline for uspace/lib/math/generic/trunc.c
- Timestamp:
- 2014-09-12T03:45:25Z (11 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- c53b58e
- Parents:
- 3eb0c85 (diff), 105d8d6 (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the(diff)links above to see all the changes relative to each parent. - File:
-
- 1 moved
-
uspace/lib/math/generic/trunc.c (moved) (moved from kernel/arch/arm32/src/ddi/ddi.c ) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
-
uspace/lib/math/generic/trunc.c
r3eb0c85 r8e7c9fe 1 1 /* 2 * Copyright (c) 20 06 Jakub Jermar2 * Copyright (c) 2014 Martin Decky 3 3 * All rights reserved. 4 4 * … … 27 27 */ 28 28 29 /** @addtogroup arm32ddi29 /** @addtogroup libmath 30 30 * @{ 31 31 */ 32 32 /** @file 33 * @brief DDI.34 33 */ 35 34 36 #include <ddi/ddi.h> 37 #include <proc/task.h> 38 #include <typedefs.h> 35 #include <mathtypes.h> 36 #include <trunc.h> 39 37 40 /** Enable I/O space range for task.38 /** Truncate fractional part (round towards zero) 41 39 * 42 * Interrupts are disabled and task is locked. 40 * Truncate the fractional part of IEEE 754 double 41 * precision floating point number by zeroing fraction 42 * bits, effectively rounding the number towards zero 43 * to the nearest whole number. 43 44 * 44 * @param task Task. 45 * @param ioaddr Startign I/O space address. 46 * @param size Size of the enabled I/O range. 45 * If the argument is infinity or NaN, an exception 46 * should be indicated. This is not implemented yet. 47 47 * 48 * @return 0 on success or an error code from errno.h. 48 * @param val Floating point number. 49 * 50 * @return Number rounded towards zero. 51 * 49 52 */ 50 int ddi_iospace_enable_arch(task_t *task, uintptr_t ioaddr, size_t size)53 float64 trunc_float64(float64 val) 51 54 { 52 return 0; 55 int32_t exp = val.parts.exp - FLOAT64_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 >= FLOAT64_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 &= UINT64_C(0x000fffffffffffff) >> exp; 71 } 72 73 return val; 53 74 } 54 75
Note:
See TracChangeset
for help on using the changeset viewer.
