Changeset 992ffa6 in mainline for uspace/lib/math/generic/trunc.c


Ignore:
Timestamp:
2015-09-04T06:40:20Z (10 years ago)
Author:
Jiri Svoboda <jiri@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
01cdd5a
Parents:
bae1e1f
Message:

Add exp(f), log(f), pow(f). Improve precision of sin, cos.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • uspace/lib/math/generic/trunc.c

    rbae1e1f r992ffa6  
    3535#include <mathtypes.h>
    3636#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 */
     53float32 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}
    3775
    3876/** Truncate fractional part (round towards zero)
Note: See TracChangeset for help on using the changeset viewer.