Source code for cake.functions.trigonometry
from __future__ import annotations
from typing import Any
from cake.core.functions import Function
import cake
from math import *
[docs]class Sin(Function):
''' Sin function '''
def _handler(self, v, **opts) -> Any:
if opts.get('rad'):
v = cake.to_radians(v)
if opts.get('prehandle'):
v = self.prehandler(v)
try:
return cake.Real(sin(v))
except Exception:
return Sin(v)
[docs]class Cos(Function):
''' Cos function '''
def _handler(self, v, **opts) -> Any:
if opts.get('rad'):
v = cake.to_radians(v)
if opts.get('prehandle'):
v = self.prehandler(v)
try:
return cake.Real(cos(v))
except Exception:
return Cos(v)
[docs]class Tan(Function):
''' tan function '''
def _handler(self, v, **opts) -> Any:
if opts.get('rad'):
v = cake.to_radians(v)
if opts.get('prehandle'):
v = self.prehandler(v)
try:
return cake.Real(tan(v))
except Exception:
return Tan(v)
[docs]class ASin(Function):
''' arc sin or inverse sin function '''
def _handler(self, v, **opts) -> Any:
if opts.get('rad'):
v = cake.to_radians(v)
if opts.get('prehandle'):
v = self.prehandler(v)
try:
return cake.Real(asin(v))
except Exception:
return ASin(v)
[docs]class ACos(Function):
''' arc cos or inverse cos function '''
def _handler(self, v, **opts) -> Any:
if opts.get('rad'):
v = cake.to_radians(v)
if opts.get('prehandle'):
v = self.prehandler(v)
try:
return cake.Real(acos(v))
except Exception:
return ACos(v)
[docs]class ATan(Function):
''' arc tan or inverse tan function '''
def _handler(self, v, **opts) -> Any:
if opts.get('rad'):
v = cake.to_radians(v)
if opts.get('prehandle'):
v = self.prehandler(v)
try:
return cake.Real(atan(v))
except Exception:
return ATan(v)
[docs]class ATan2(Function):
''' arc tan2 or inverse tan2 function '''
def _handler(self, v, **opts) -> Any:
if opts.get('rad'):
v = cake.to_radians(v)
if opts.get('prehandle'):
v = self.prehandler(v)
try:
return cake.Real(atan2(v))
except Exception:
return ATan2(v)
[docs]class SinH(Function):
''' Hyperbolic sin function '''
def _handler(self, v, **opts) -> Any:
if opts.get('rad'):
v = cake.to_radians(v)
if opts.get('prehandle'):
v = self.prehandler(v)
try:
return cake.Real(sinh(v))
except Exception:
return SinH(v)
[docs]class CosH(Function):
''' Hyperbolic cos function '''
def _handler(self, v, **opts) -> Any:
if opts.get('rad'):
v = cake.to_radians(v)
if opts.get('prehandle'):
v = self.prehandler(v)
try:
return cake.Real(cosh(v))
except Exception:
return CosH(v)
[docs]class TanH(Function):
''' Hyperbolic tan function '''
def _handler(self, v, **opts) -> Any:
if opts.get('rad'):
v = cake.to_radians(v)
if opts.get('prehandle'):
v = self.prehandler(v)
try:
return cake.Real(tanh(v))
except Exception:
return TanH(v)
[docs]class ASinH(Function):
''' Arc hyperbolic sin or inverse hyperbolic sin function '''
def _handler(self, v, **opts) -> Any:
if opts.get('rad'):
v = cake.to_radians(v)
if opts.get('prehandle'):
v = self.prehandler(v)
try:
return cake.Real(asinh(v))
except Exception:
return ASinH(v)
[docs]class ACosH(Function):
''' Arc hyperbolic cos or inverse hyperbolic cos function '''
def _handler(self, v, **opts) -> Any:
if opts.get('rad'):
v = cake.to_radians(v)
if opts.get('prehandle'):
v = self.prehandler(v)
try:
return cake.Real(acosh(v))
except Exception:
return ACosH(v)
[docs]class ATanH(Function):
''' Arc hyperbolic tan or inverse hyperbolic tan function '''
def _handler(self, v, **opts) -> Any:
if opts.get('rad'):
v = cake.to_radians(v)
if opts.get('prehandle'):
v = self.prehandler(v)
try:
return cake.Real(atanh(v))
except Exception:
return ATanH(v)