Changeset 1022


Ignore:
Timestamp:
Oct 13, 2011, 1:31:14 AM (9 years ago)
Author:
sam
Message:

core: implement pow() for real numbers; for now special cases such as
negative zero or negative nth roots are not handled.

Location:
trunk/src
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/real.cpp

    r1021 r1022  
    589589
    590590    return ret;
     591}
     592
     593real pow(real const &x, real const &y)
     594{
     595    if (!y)
     596        return real::R_1;
     597    if (!x)
     598        return real::R_0;
     599    if (x > real::R_0)
     600        return exp(y * log(x));
     601    else /* x < 0 */
     602    {
     603        if (y == round(y))
     604            return -exp(y * log(-x));
     605        /* FIXME: negative nth root */
     606        return real::R_0;
     607    }
    591608}
    592609
     
    10131030}
    10141031
     1032void real::hexprint() const
     1033{
     1034    printf("%08x", m_signexp);
     1035    for (int i = 0; i < BIGITS; i++)
     1036        printf(" %08x", m_mantissa[i]);
     1037    printf("\n");
     1038}
     1039
    10151040void real::print(int ndigits) const
    10161041{
  • trunk/src/real.h

    r1019 r1022  
    8686    friend real sqrt(real const &x);
    8787    friend real cbrt(real const &x);
    88     /* FIXME: pow */
     88    friend real pow(real const &x, real const &y);
    8989
    9090    /* Rounding, absolute value, remainder etc. */
     
    9696    friend real fmod(real const &x, real const &y);
    9797
     98    void hexprint() const;
    9899    void print(int ndigits = 150) const;
    99100
Note: See TracChangeset for help on using the changeset viewer.