Changeset 8e7c9fe in mainline for uspace/lib/math/generic/trunc.c


Ignore:
Timestamp:
2014-09-12T03:45:25Z (11 years ago)
Author:
Jan Vesely <jano.vesely@…>
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.
Message:

merge mainline changes

most usb changes were reverted. blink and usbmass were fixed
known problems:
ehci won't initialize
usbmast asserts on unmount (happens on mainline too)

File:
1 moved

Legend:

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

    r3eb0c85 r8e7c9fe  
    11/*
    2  * Copyright (c) 2006 Jakub Jermar
     2 * Copyright (c) 2014 Martin Decky
    33 * All rights reserved.
    44 *
     
    2727 */
    2828
    29 /** @addtogroup arm32ddi
     29/** @addtogroup libmath
    3030 * @{
    3131 */
    3232/** @file
    33  *  @brief DDI.
    3433 */
    3534
    36 #include <ddi/ddi.h>
    37 #include <proc/task.h>
    38 #include <typedefs.h>
     35#include <mathtypes.h>
     36#include <trunc.h>
    3937
    40 /** Enable I/O space range for task.
     38/** Truncate fractional part (round towards zero)
    4139 *
    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.
    4344 *
    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.
    4747 *
    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 *
    4952 */
    50 int ddi_iospace_enable_arch(task_t *task, uintptr_t ioaddr, size_t size)
     53float64 trunc_float64(float64 val)
    5154{
    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;
    5374}
    5475
Note: See TracChangeset for help on using the changeset viewer.