Ignore:
Timestamp:
Jan 12, 2012, 12:36:29 AM (11 years ago)
Author:
sam
Message:

math: implement ulp() for reals, which returns the smallest real y > 0 such
that x + y != x, and nextafter() which behaves like the C function.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/real.cpp

    r1128 r1130  
    939939}
    940940
     941real ulp(real const &x)
     942{
     943    real ret = real::R_1;
     944    if (x)
     945        ret.m_signexp = x.m_signexp + 1 - real::BIGITS * real::BIGIT_BITS;
     946    else
     947        ret.m_signexp = 0;
     948    return ret;
     949}
     950
     951real nextafter(real const &x, real const &y)
     952{
     953    if (x == y)
     954        return x;
     955    else if (x < y)
     956        return x + ulp(x);
     957    else
     958        return x - ulp(x);
     959}
     960
    941961real copysign(real const &x, real const &y)
    942962{
Note: See TracChangeset for help on using the changeset viewer.