Python math.atanh() Examples

The following are code examples for showing how to use math.atanh(). They are from open source Python projects. You can vote up the examples you like or vote down the ones you don't like.

Example 1
Project: ironpython2   Author: IronLanguages   File: test_math.py    Apache License 2.0 6 votes vote down vote up
def test_math_subclass(self):
        """verify subtypes of float/long work w/ math functions"""
        import math
        class myfloat(float): pass
        class mylong(long): pass

        mf = myfloat(1)
        ml = mylong(1)

        for x in math.log, math.log10, math.log1p, math.asinh, math.acosh, math.atanh, math.factorial, math.trunc, math.isinf:
            try:
                resf = x(mf)
            except ValueError:
                resf = None
            try:
                resl = x(ml)
            except ValueError:
                resl = None
            self.assertEqual(resf, resl) 
Example 2
Project: duct   Author: ducted   File: generator.py    MIT License 6 votes vote down vote up
def get(self):
        self.x += self.config.get('dx', 0.1)

        val = eval(self.config.get('function', 'sin(x)'), {
            'sin': math.sin,
            'sinh': math.sinh,
            'cos': math.cos,
            'cosh': math.cosh,
            'tan': math.tan,
            'tanh': math.tanh,
            'asin': math.asin,
            'acos': math.acos,
            'atan': math.atan,
            'asinh': math.asinh,
            'acosh': math.acosh,
            'atanh': math.atanh,
            'log': math.log,
            'abs': abs,
            'e': math.e,
            'pi': math.pi,
            'x': self.x
        })

        return self.createEvent('ok', 'Sine wave', val) 
Example 3
Project: vidaug   Author: okankop   File: temporal.py    MIT License 6 votes vote down vote up
def _get_distorted_indices(self, nb_images):
        inverse = random.randint(0, 1)

        if inverse:
            scale = random.random()
            scale *= 0.21
            scale += 0.6
        else:
            scale = random.random()
            scale *= 0.6
            scale += 0.8

        frames_per_clip = nb_images

        indices = np.linspace(-scale, scale, frames_per_clip).tolist()
        if inverse:
            values = [math.atanh(x) for x in indices]
        else:
            values = [math.tanh(x) for x in indices]

        values = [x / values[-1] for x in values]
        values = [int(round(((x + 1) / 2) * (frames_per_clip - 1), 0)) for x in values]
        return values 
Example 4
Project: pyblish-win   Author: pyblish   File: test_math.py    GNU Lesser General Public License v3.0 5 votes vote down vote up
def testAtanh(self):
        self.assertRaises(TypeError, math.atan)
        self.ftest('atanh(0)', math.atanh(0), 0)
        self.ftest('atanh(0.5)', math.atanh(0.5), 0.54930614433405489)
        self.ftest('atanh(-0.5)', math.atanh(-0.5), -0.54930614433405489)
        self.assertRaises(ValueError, math.atanh, 1)
        self.assertRaises(ValueError, math.atanh, -1)
        self.assertRaises(ValueError, math.atanh, INF)
        self.assertRaises(ValueError, math.atanh, NINF)
        self.assertTrue(math.isnan(math.atanh(NAN))) 
Example 5
Project: exposure   Author: yuanming-hu   File: util.py    MIT License 5 votes vote down vote up
def tanh_range(l, r, initial=None):

  def get_activation(left, right, initial):

    def activation(x):
      if initial is not None:
        bias = math.atanh(2 * (initial - left) / (right - left) - 1)
      else:
        bias = 0
      return tanh01(x + bias) * (right - left) + left

    return activation

  return get_activation(l, r, initial) 
Example 6
Project: RouteOptimization   Author: andre-le   File: geomath.py    MIT License 5 votes vote down vote up
def atanh(x):
    """atanh(x) (missing from python 2.5.2)"""

    if sys.version_info > (2, 6):
      return math.atanh(x)

    y = abs(x)                  # Enforce odd parity
    y = Math.log1p(2 * y/(1 - y))/2
    return -y if x < 0 else y 
Example 7
Project: NiujiaoDebugger   Author: MrSrc   File: test_math.py    GNU General Public License v3.0 5 votes vote down vote up
def testAtanh(self):
        self.assertRaises(TypeError, math.atan)
        self.ftest('atanh(0)', math.atanh(0), 0)
        self.ftest('atanh(0.5)', math.atanh(0.5), 0.54930614433405489)
        self.ftest('atanh(-0.5)', math.atanh(-0.5), -0.54930614433405489)
        self.assertRaises(ValueError, math.atanh, 1)
        self.assertRaises(ValueError, math.atanh, -1)
        self.assertRaises(ValueError, math.atanh, INF)
        self.assertRaises(ValueError, math.atanh, NINF)
        self.assertTrue(math.isnan(math.atanh(NAN))) 
Example 8
Project: linien   Author: hermitdemschoenenleben   File: cordic.py    GNU General Public License v3.0 5 votes vote down vote up
def _constants(self, stages, bits):
        if self.func_mode == "circular":
            s = range(stages)
            a = [atan(2**-i) for i in s]
            g = [sqrt(1 + 2**(-2*i)) for i in s]
            #zmax = sum(a)
            # use pi anyway as the input z can cause overflow
            # and we need the range for quadrant mapping
            zmax = pi
        elif self.func_mode == "linear":
            s = range(stages)
            a = [2**-i for i in s]
            g = [1 for i in s]
            #zmax = sum(a)
            # use 2 anyway as this simplifies a and scaling
            zmax = 2.
        else:  # hyperbolic
            s = []
            # need to repeat some stages:
            j = 4
            for i in range(stages):
                if i == j:
                    s.append(j)
                    j = 3*j + 1
                s.append(i + 1)
            a = [atanh(2**-i) for i in s]
            g = [sqrt(1 - 2**(-2*i)) for i in s]
            zmax = sum(a)*2
        # round here helps the width=2**i - 1 case but hurts the
        # important width=2**i case
        cast = int
        if log(bits)/log(2) % 1:
            cast = round
        a = [cast(ai*2**(bits - 1)/zmax) for ai in a]
        gain = 1.
        for gi in g:
            gain *= gi
        return a, s, zmax, gain 
Example 9
Project: rpython-lang-scheme   Author: tomoh1r   File: rfloat.py    MIT License 5 votes vote down vote up
def atanh(x):
        "NOT_RPYTHON"
        if isnan(x):
            return x
        absx = abs(x)
        if absx >= 1.:
            raise ValueError("math domain error")
        if absx < _2_to_m28:
            return x
        if absx < .5:
            t = absx + absx
            t = .5 * log1p(t + t * absx / (1. - absx))
        else:
            t = .5 * log1p((absx + absx) / (1. - absx))
        return copysign(t, x) 
Example 10
Project: ironpython2   Author: IronLanguages   File: test_math.py    Apache License 2.0 5 votes vote down vote up
def testAtanh(self):
        self.assertRaises(TypeError, math.atan)
        self.ftest('atanh(0)', math.atanh(0), 0)
        self.ftest('atanh(0.5)', math.atanh(0.5), 0.54930614433405489)
        self.ftest('atanh(-0.5)', math.atanh(-0.5), -0.54930614433405489)
        self.assertRaises(ValueError, math.atanh, 1)
        self.assertRaises(ValueError, math.atanh, -1)
        self.assertRaises(ValueError, math.atanh, INF)
        self.assertRaises(ValueError, math.atanh, NINF)
        self.assertTrue(math.isnan(math.atanh(NAN))) 
Example 11
Project: Blockly-rduino-communication   Author: technologiescollege   File: test_math.py    GNU General Public License v3.0 5 votes vote down vote up
def testAtanh(self):
        self.assertRaises(TypeError, math.atan)
        self.ftest('atanh(0)', math.atanh(0), 0)
        self.ftest('atanh(0.5)', math.atanh(0.5), 0.54930614433405489)
        self.ftest('atanh(-0.5)', math.atanh(-0.5), -0.54930614433405489)
        self.assertRaises(ValueError, math.atanh, 1)
        self.assertRaises(ValueError, math.atanh, -1)
        self.assertRaises(ValueError, math.atanh, INF)
        self.assertRaises(ValueError, math.atanh, NINF)
        self.assertTrue(math.isnan(math.atanh(NAN))) 
Example 12
Project: cqp-sdk-for-py37-native   Author: crud-boy   File: test_math.py    GNU General Public License v2.0 5 votes vote down vote up
def testAtanh(self):
        self.assertRaises(TypeError, math.atan)
        self.ftest('atanh(0)', math.atanh(0), 0)
        self.ftest('atanh(0.5)', math.atanh(0.5), 0.54930614433405489)
        self.ftest('atanh(-0.5)', math.atanh(-0.5), -0.54930614433405489)
        self.assertRaises(ValueError, math.atanh, 1)
        self.assertRaises(ValueError, math.atanh, -1)
        self.assertRaises(ValueError, math.atanh, INF)
        self.assertRaises(ValueError, math.atanh, NINF)
        self.assertTrue(math.isnan(math.atanh(NAN))) 
Example 13
Project: oss-ftp   Author: aliyun   File: test_math.py    MIT License 5 votes vote down vote up
def testAtanh(self):
        self.assertRaises(TypeError, math.atan)
        self.ftest('atanh(0)', math.atanh(0), 0)
        self.ftest('atanh(0.5)', math.atanh(0.5), 0.54930614433405489)
        self.ftest('atanh(-0.5)', math.atanh(-0.5), -0.54930614433405489)
        self.assertRaises(ValueError, math.atanh, 1)
        self.assertRaises(ValueError, math.atanh, -1)
        self.assertRaises(ValueError, math.atanh, INF)
        self.assertRaises(ValueError, math.atanh, NINF)
        self.assertTrue(math.isnan(math.atanh(NAN))) 
Example 14
Project: gen_tree   Author: C38C   File: lib.py    GNU General Public License v3.0 5 votes vote down vote up
def area_ellipsoid(c, a):
    e = (1 - (c**2/a**2))**0.5
    return 2 * math.pi * a**2 * (1 + (1 - e**2) / e * math.atanh(e)) 
Example 15
Project: ufora   Author: ufora   File: pure_math.py    Apache License 2.0 5 votes vote down vote up
def __call__(self, val):
        if val >= 1:
            raise ValueError("math domain error")

        return __inline_fora(
            """fun(@unnamed_args:(val), *args) {
                   PyFloat(math.atanh([email protected]))
                   }"""
            )(val) 
Example 16
Project: ufora   Author: ufora   File: MathTestCases.py    Apache License 2.0 5 votes vote down vote up
def test_pure_python_math_module(self):
        vals = [1, -.5, 1.5, 0, 0.0, -2, -2.2, .2]

        # not being tested: math.asinh, math.atanh, math.lgamma, math.erfc, math.acos
        def f():
            functions = [
                math.sqrt, math.cos, math.sin, math.tan, math.asin, math.atan,
                math.acosh, math.cosh, math.sinh, math.tanh, math.ceil,
                math.erf, math.exp, math.expm1, math.factorial, math.floor,
                math.log, math.log10, math.log1p
            ]
            tr = []
            for idx1 in range(len(vals)):
                v1 = vals[idx1]
                for funIdx in range(len(functions)):
                    function = functions[funIdx]
                    try:
                        tr = tr + [function(v1)]
                    except ValueError as ex:
                        pass

            return tr

        r1 = self.evaluateWithExecutor(f)
        r2 = f()
        self.assertGreater(len(r1), 100)
        self.assertTrue(numpy.allclose(r1, r2, 1e-6)) 
Example 17
Project: hask   Author: billpmurphy   File: Num.py    BSD 2-Clause "Simplified" License 5 votes vote down vote up
def make_instance(typeclass, cls, pi, exp, sqrt, log, pow, logBase, sin,
            tan, cos, asin, atan, acos, sinh, tanh, cosh, asinh, atanh, acosh):
        attrs = {"pi":pi, "exp":exp, "sqrt":sqrt, "log":log, "pow":pow,
                "logBase":logBase, "sin":sin, "tan":tan, "cos":cos,
                "asin":asin, "atan":atan, "acos":acos, "sinh":sinh,
                "tanh":tanh, "cosh":cosh, "asinh":asinh, "atanh":atanh,
                "acosh":acosh}
        build_instance(Floating, cls, attrs)
        return 
Example 18
Project: hask   Author: billpmurphy   File: Num.py    BSD 2-Clause "Simplified" License 5 votes vote down vote up
def atanh(x):
    """
    atanh :: Floating a => a -> a
    """
    return Floating[x].atanh(x) 
Example 19
Project: hotxlfp   Author: aidhound   File: mathtrig.py    MIT License 5 votes vote down vote up
def ATANH(number):
    number = utils.parse_number(number)
    if isinstance(number, error.XLError):
        return number
    return math.atanh(number) 
Example 20
Project: social_ethosa   Author: Ethosa   File: BotWrapper.py    GNU Lesser General Public License v3.0 5 votes vote down vote up
def calc(self, text):
        """calculator

        Arguments:
            text {[str]} -- [example for calculation]

        Returns:
            [str] -- [result]
        """
        self.count_use += 1
        text = text.replace("^", "**")  # ''.join(i for i in text if i in self.validate_for_calc)
        glb = {
            "pi": math.pi, "e": math.e,
            "sin": math.sin, "cos": math.cos,
            "factorial": math.factorial, "ceil": math.ceil,
            "floor": math.floor, 'exit': lambda *args: " ".join(args),
            "pow": math.pow, "log": math.log,
            "sqrt": math.sqrt, "tan": math.tan,
            "arccos": math.acos, "arcsin": math.asin,
            "arctan": math.atan, "degrees": math.degrees,
            "radians": math.radians, "sinh": math.sinh,
            "cosh": math.cosh, "tanh": math.tanh,
            "arccosh": math.acosh, "arcsinh": math.asinh,
            "arctanh": math.atanh, 'print': lambda *args: " ".join(args)
        }
        return eval(text, glb, {}) 
Example 21
Project: PyFlow   Author: wonderworks-software   File: MathLib.py    Apache License 2.0 5 votes vote down vote up
def atanh(x=('FloatPin', 0.0), Result=(REF, ('BoolPin', False))):
        '''Return the inverse hyperbolic tangent of `x`.'''
        try:
            Result(True)
            return math.atanh(x)
        except:
            Result(False)
            return -1 
Example 22
Project: m-stp   Author: MukeunKim   File: core.py    MIT License 5 votes vote down vote up
def atanh(x):
    if isinstance(x, LineValue): lx = x.get_value()
    else: lx = x
    if lx == NAN: return LineValue(NAN)
    return LineValue(math.atanh(lx)) 
Example 23
Project: gpxdata   Author: MauriceS   File: gpxdata.py    GNU General Public License v3.0 5 votes vote down vote up
def transMercator (cls, lat, lon, centerlon=0.0):
        """
        Transversal Mercator projection - returns (x,y) tuple (unit:  m)

        centerlon = longitude [degrees] of central meridian (x=0)
        """
        lat_rad = math.radians(lat)
        lon_rad = math.radians(lon-centerlon)
        x = cls.r_earth * math.atanh(math.sin(lon_rad) * math.cos(lat_rad))
        y = cls.r_earth * math.atan(math.tan(lat_rad) / math.cos(lon_rad))
        return x,y 
Example 24
Project: femtocode   Author: diana-hep   File: test_libstandard.py    Apache License 2.0 5 votes vote down vote up
def test_atanh(self):
        self.assertEqual(session.source("Test", x=real(0.1, 0.5)).type("atanh(x)"), real(math.atanh(0.1), math.atanh(0.5)))
        self.assertEqual(session.source("Test", x=real(0.1, almost(0.5))).type("atanh(x)"), real(math.atanh(0.1), almost(math.atanh(0.5))))
        self.assertEqual(session.source("Test", x=real(0.1, 1.0)).type("atanh(x)"), real(math.atanh(0.1), inf))
        self.assertEqual(session.source("Test", x=real(0.1, almost(1.0))).type("atanh(x)"), real(math.atanh(0.1), almost(inf)))
        self.assertEqual(session.source("Test", x=real(-1.0, 0.5)).type("atanh(x)"), real(-inf, math.atanh(0.5)))
        self.assertEqual(session.source("Test", x=real(almost(-1.0), 0.5)).type("atanh(x)"), real(almost(-inf), math.atanh(0.5)))
        self.assertRaises(FemtocodeError, lambda: session.source("Test", x=real(0.1, 1.1)).type("atanh(x)"))
        self.assertRaises(FemtocodeError, lambda: session.source("Test", x=real(0.1, almost(1.1))).type("atanh(x)"))
        self.assertRaises(FemtocodeError, lambda: session.source("Test", x=real(-1.1, 0.5)).type("atanh(x)"))
        self.assertRaises(FemtocodeError, lambda: session.source("Test", x=real(almost(-1.1), 0.5)).type("atanh(x)"))
        for entry in numerical.toPython(ylim2 = "ylim2", a = "atanh(ylim2 / 10)").submit():
            self.assertEqual(entry.a, math.atanh(entry.ylim2 / 10)) 
Example 25
Project: InventorLoader   Author: jmplonka   File: Acis.py    GNU General Public License v2.0 5 votes vote down vote up
def ARCTANH(x):    return (atanh(x)) 
Example 26
Project: Project-New-Reign---Nemesis-Main   Author: ShikyoKira   File: test_math.py    GNU General Public License v3.0 5 votes vote down vote up
def testAtanh(self):
        self.assertRaises(TypeError, math.atan)
        self.ftest('atanh(0)', math.atanh(0), 0)
        self.ftest('atanh(0.5)', math.atanh(0.5), 0.54930614433405489)
        self.ftest('atanh(-0.5)', math.atanh(-0.5), -0.54930614433405489)
        self.assertRaises(ValueError, math.atanh, 1)
        self.assertRaises(ValueError, math.atanh, -1)
        self.assertRaises(ValueError, math.atanh, INF)
        self.assertRaises(ValueError, math.atanh, NINF)
        self.assertTrue(math.isnan(math.atanh(NAN))) 
Example 27
Project: cells   Author: AlesTsurko   File: test_math.py    MIT License 5 votes vote down vote up
def testAtanh(self):
        self.assertRaises(TypeError, math.atan)
        self.ftest('atanh(0)', math.atanh(0), 0)
        self.ftest('atanh(0.5)', math.atanh(0.5), 0.54930614433405489)
        self.ftest('atanh(-0.5)', math.atanh(-0.5), -0.54930614433405489)
        self.assertRaises(ValueError, math.atanh, 1)
        self.assertRaises(ValueError, math.atanh, -1)
        self.assertRaises(ValueError, math.atanh, INF)
        self.assertRaises(ValueError, math.atanh, NINF)
        self.assertTrue(math.isnan(math.atanh(NAN))) 
Example 28
Project: qgis-shapetools-plugin   Author: NationalSecurityAgency   File: geomath.py    GNU General Public License v2.0 5 votes vote down vote up
def atanh(x):
    """atanh(x) (missing from python 2.5.2)"""

    if sys.version_info > (2, 6):
      return math.atanh(x)

    y = abs(x)                  # Enforce odd parity
    y = Math.log1p(2 * y/(1 - y))/2
    return -y if x < 0 else y 
Example 29
Project: data_algebra   Author: WinVector   File: SQLite.py    BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
def prepare_connection(self, conn):
        # https://docs.python.org/3/library/sqlite3.html#sqlite3.Connection.create_function
        conn.create_function("is_bad", 1, _check_scalar_bad)
        # math fns
        conn.create_function("acos", 1, math.acos)
        conn.create_function("acosh", 1, math.acosh)
        conn.create_function("asin", 1, math.asin)
        conn.create_function("asinh", 1, math.asinh)
        conn.create_function("atan", 1, math.atan)
        conn.create_function("atanh", 1, math.atanh)
        conn.create_function("ceil", 1, math.ceil)
        conn.create_function("cos", 1, math.cos)
        conn.create_function("cosh", 1, math.cosh)
        conn.create_function("degrees", 1, math.degrees)
        conn.create_function("erf", 1, math.erf)
        conn.create_function("erfc", 1, math.erfc)
        conn.create_function("exp", 1, math.exp)
        conn.create_function("expm1", 1, math.expm1)
        conn.create_function("fabs", 1, math.fabs)
        conn.create_function("factorial", 1, math.factorial)
        conn.create_function("floor", 1, math.floor)
        conn.create_function("frexp", 1, math.frexp)
        conn.create_function("gamma", 1, math.gamma)
        conn.create_function("isfinite", 1, math.isfinite)
        conn.create_function("isinf", 1, math.isinf)
        conn.create_function("isnan", 1, math.isnan)
        conn.create_function("lgamma", 1, math.lgamma)
        conn.create_function("log", 1, math.log)
        conn.create_function("log10", 1, math.log10)
        conn.create_function("log1p", 1, math.log1p)
        conn.create_function("log2", 1, math.log2)
        conn.create_function("modf", 1, math.modf)
        conn.create_function("radians", 1, math.radians)
        conn.create_function("sin", 1, math.sin)
        conn.create_function("sinh", 1, math.sinh)
        conn.create_function("sqrt", 1, math.sqrt)
        conn.create_function("tan", 1, math.tan)
        conn.create_function("tanh", 1, math.tanh)
        conn.create_function("trunc", 1, math.trunc)
        conn.create_function("atan2", 2, math.atan2)
        conn.create_function("copysign", 2, math.copysign)
        conn.create_function("fmod", 2, math.fmod)
        conn.create_function("gcd", 2, math.gcd)
        conn.create_function("hypot", 2, math.hypot)
        conn.create_function("isclose", 2, math.isclose)
        conn.create_function("ldexp", 2, math.ldexp)
        conn.create_function("pow", 2, math.pow) 
Example 30
Project: data_algebra   Author: WinVector   File: SQLite.py    BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
def prepare_connection(self, conn):
        # https://docs.python.org/3/library/sqlite3.html#sqlite3.Connection.create_function
        conn.create_function("is_bad", 1, _check_scalar_bad)
        # math fns
        conn.create_function("acos", 1, math.acos)
        conn.create_function("acosh", 1, math.acosh)
        conn.create_function("asin", 1, math.asin)
        conn.create_function("asinh", 1, math.asinh)
        conn.create_function("atan", 1, math.atan)
        conn.create_function("atanh", 1, math.atanh)
        conn.create_function("ceil", 1, math.ceil)
        conn.create_function("cos", 1, math.cos)
        conn.create_function("cosh", 1, math.cosh)
        conn.create_function("degrees", 1, math.degrees)
        conn.create_function("erf", 1, math.erf)
        conn.create_function("erfc", 1, math.erfc)
        conn.create_function("exp", 1, math.exp)
        conn.create_function("expm1", 1, math.expm1)
        conn.create_function("fabs", 1, math.fabs)
        conn.create_function("factorial", 1, math.factorial)
        conn.create_function("floor", 1, math.floor)
        conn.create_function("frexp", 1, math.frexp)
        conn.create_function("gamma", 1, math.gamma)
        conn.create_function("isfinite", 1, math.isfinite)
        conn.create_function("isinf", 1, math.isinf)
        conn.create_function("isnan", 1, math.isnan)
        conn.create_function("lgamma", 1, math.lgamma)
        conn.create_function("log", 1, math.log)
        conn.create_function("log10", 1, math.log10)
        conn.create_function("log1p", 1, math.log1p)
        conn.create_function("log2", 1, math.log2)
        conn.create_function("modf", 1, math.modf)
        conn.create_function("radians", 1, math.radians)
        conn.create_function("sin", 1, math.sin)
        conn.create_function("sinh", 1, math.sinh)
        conn.create_function("sqrt", 1, math.sqrt)
        conn.create_function("tan", 1, math.tan)
        conn.create_function("tanh", 1, math.tanh)
        conn.create_function("trunc", 1, math.trunc)
        conn.create_function("atan2", 2, math.atan2)
        conn.create_function("copysign", 2, math.copysign)
        conn.create_function("fmod", 2, math.fmod)
        conn.create_function("gcd", 2, math.gcd)
        conn.create_function("hypot", 2, math.hypot)
        conn.create_function("isclose", 2, math.isclose)
        conn.create_function("ldexp", 2, math.ldexp)
        conn.create_function("pow", 2, math.pow)