Code coverage report for fdlibm/acosh.js

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

All files » fdlibm/ » acosh.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                                                    1 9   2   7   3   1     2   4   1   3   1 1     2 2      
//
// ====================================================
// 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_acosh(x)
// Method :
//      Based on 
//              acosh(x) = log [ x + sqrt(x*x-1) ]
//      we have
//              acosh(x) := log(x)+ln2, if x is large; else
//              acosh(x) := log(2x-1/(sqrt(x*x-1)+x)) if x>2; else
//              acosh(x) := log1p(t+sqrt(2.0*t+t*t)); where t=x-1.
//
// Special cases:
//      acosh(x) is NaN with signal if x<1.
//      acosh(NaN) is NaN without signal.
//
 
function acosh (x) {
    if (x < 1) {
        // x < 1 -> acosh = NaN
        return Infinity - Infinity;
    }
    if (x > Math.pow(2,28)) {
        // x > 2^28
        if (!isFinite(x)) {
            // x is infinite or NaN. Return infinity or NaN
            return x + x;
        }
        // acosh(huge) = log(2*x) = log(x) + log(2)
        return Math.log(x) + Math.LN2;
    }
    if (x === 1) {
        // acosh(1) = 0
        return 0;
    }
    if (x > 2) {
        // 2^28 > x > 2
        var t = x * x;
        return Math.log(2*x - 1/(x + Math.sqrt(t - 1)));
    }
    // 1 < x <= 2
    var t = x - 1;
    return log1p(t + Math.sqrt(2*t + t*t));
}