6.6 EXP function

EXP
## function (x) 
## {
##     if (is.nan(x)) {
##         warning("Input is NaN.")
##         return(NaN)
##     }
##     else if (x == +Inf) {
##         warning("Input is +Inf.")
##         return(+Inf)
##     }
##     else if (x == -Inf) {
##         warning("Input is -Inf.")
##         return(-Inf)
##     }
##     else if (x == 0) {
##         return(1)
##     }
##     if (x < 0) {
##         x = -x
##         Neg = TRUE
##     }
##     else {
##         Neg = FALSE
##     }
##     if (x > 0.9 * .Machine$double.xmax) {
##         if (Neg) {
##             return(0)
##         }
##         else {
##             warning("+Inf produced")
##             return(+Inf)
##         }
##     }
##     else {
##         p0 = 3.15551927656846e-05
##         p1 = 0.00757531801594228
##         p2 = 0.25
##         q0 = 7.510402839987e-07
##         q1 = 0.000631218943743985
##         q2 = 0.0568173026985512
##         q3 = 0.5
##         c1 = 22713/32768
##         c2 = 1.42860682030942e-06
##         invln2 = 1.44269504088896
##         Rteps = SQRT(.Machine$double.eps)
##         xexp = x * invln2
##         g = x - xexp * c1 - xexp * c2
##         if (g > -Rteps & g < Rteps) {
##             x1 = 1
##         }
##         else {
##             y = g * g
##             g = g * ((p0 * y + p1) * y + p2)
##             x1 = 0.5 + g/(((q0 * y + q1) * y + q2) * y + q3 - 
##                 g)
##             xexp = xexp + 1
##         }
##         if (Neg) {
##             x1 = 1/x1
##             xexp = -xexp
##         }
##         return(DENORM(c(x1, xexp)))
##     }
## }
## <bytecode: 0x000001e2afe0b9b0>
## <environment: namespace:math>

Practice Script

format(EXP(10), digits=22)
## [1] "22026.46579480672517093"
format(exp(10), digits=22)
## [1] "22026.46579480671789497"
# Closest value of exp(10) = 22026. 46579 48067 1652

Explore related functions such as expm1 log1p.