Code coverage report for fdlibm/sinh.js

Statements: 100% (19 / 19)      Branches: 100% (14 / 14)      Functions: 100% (1 / 1)      Lines: 100% (19 / 19)      Ignored: none     

All files » fdlibm/ » sinh.js
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70                                                          1   3023 3     3020     3020 3020 2632   1946   686 686 58   628         388 382         6 2 2 2         4    
//
// ====================================================
// Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
//
// Developed at SunSoft, a Sun Microsystems, Inc. business.
// Permission to use, copy, modify, and distribute this
// software is freely granted, provided that this notice 
// is preserved.
// ====================================================
//
 
// __ieee754_sinh(x)
// Method : 
// mathematically sinh(x) if defined to be (exp(x)-exp(-x))/2
//      1. Replace x by |x| (sinh(-x) = -sinh(x)). 
//      2. 
//                                                  E + E/(E+1)
//          0        <= x <= 22     :  sinh(x) := --------------, E=expm1(x)
//                                                      2
//
//          22       <= x <= lnovft :  sinh(x) := exp(x)/2 
//          lnovft   <= x <= ln2ovft:  sinh(x) := exp(x/2)/2 * exp(x/2)
//          ln2ovft  <  x           :  sinh(x) := x*shuge (overflow)
//
// Special cases:
//      sinh(x) is |x| if x is +INF, -INF, or NaN.
//      only sinh(0)=0 is exact for finite x.
//
 
function sinh (x) {
    // x is infinity or NaN. Return infinity or NaN.
    if (!isFinite(x)) {
        return x;
    }
 
    var h = (x < 0) ? -0.5 : 0.5;
 
    // |x| in [0, 22]. return sign(x)*0.5*(E+E/(E+1))
    var ax = Math.abs(x);
    if (ax < 22) {
        if (ax < Math.pow(2,-28)) {
            // |x| < 2^-28. sinh(tiny) = tiny
            return x;
        }
        var t = expm1(ax);
        if (ax < 1) {
            return h*(2*t - t*t/(t + 1));
        }
        return h*(t + t/(t + 1));
    }
 
    // |x| in [22, log(maxdouble)], return 0.5 * exp(|x|)
    // 0x40862e42 = high word of log(maxdouble)
    if (ax < _ConstructDouble(0x40862e42,0)) {
        return h*exp(ax);
    }
 
    // |x| in [log(maxdouble), overflowthreshold]
    // overflowthreshold = 710.4758600739439
    if (ax <= _ConstructDouble(0x408633ce, 0x8fb9f87d)) {
        var w = exp(0.5*ax);
        var t = h * w;
        return t * w;
    }
 
    // |x| > overflowthreshold, sinh(x) overflows. Return infinity of
    // the appropriate sign.
    return x*1e307;
}