Code coverage report for fdlibm/atanh.js

Statements: 100% (16 / 16)      Branches: 100% (10 / 10)      Functions: 100% (1 / 1)      Lines: 100% (16 / 16)      Ignored: none     

All files » fdlibm/ » atanh.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                                                            1 13   13   2     11   2     9   4     5 5   2 2     3     5 2   3      
//
// ====================================================
// 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_atanh(x)
// Method :
//    1.Reduced x to positive by atanh(-x) = -atanh(x)
//    2.For x>=0.5
//                  1              2x                          x
//      atanh(x) = --- * log(1 + -------) = 0.5 * log1p(2 * --------)
//                  2             1 - x                      1 - x
//      
//      For x<0.5
//      atanh(x) = 0.5*log1p(2x+2x*x/(1-x))
//
// Special cases:
//      atanh(x) is NaN if |x| > 1 with signal;
//      atanh(NaN) is that NaN with no signal;
//      atanh(+-1) is +-INF with signal.
//
//
 
function atanh (x) {
    var ax = Math.abs(x);
    
    if (ax > 1) {
        // tanh(x) = NaN for |x| > 1
        return (x - x) / (x - x);
    }
 
    if (ax == 1) {
        // tanh(+/-1) = +/-Infinity
        return x/0;
    }
 
    if (ax < Math.pow(2,-28)) {
        // tanh(x) = x for |x| < 2^-28
        return x;
    }
 
    var t;
    if (ax < 0.5) {
        // |x| < 0.5
        t = ax + ax;
        t = 0.5 * log1p(t + t*ax/(1 - ax));
    } else {
        // |x| >= 0.5
        t = 0.5 * log1p((ax + ax)/(1 - ax));
    }
 
    if (x >= 0) {
        return t;
    } else {
        return -t;
    }
}