Skip to main content

# EXP

A scalar numeric function that returns the exponential (inverse of natural logarithm) of a number.

## Synopsis

```{fn EXP(expression)}
```

### Arguments

Argument Description
expression The logarithmic exponent, which is a numeric expression.

EXP returns either the NUMERIC or DOUBLE data type. If expression is data type DOUBLE, EXP returns DOUBLE; otherwise, it returns NUMERIC.

## Description

EXP is the exponential function en, where e is the constant 2.718281828. Therefore, to return the value of e, you can specify {fn EXP(1)}. EXP is the inverse of the natural logarithm function LOG.

EXP returns a value with a precision of 36 and a scale of 18. EXP returns NULL if passed a NULL value.

EXP can only be used as an ODBC scalar function (with the curly brace syntax).

## Examples

The following example returns the constant e:

`SELECT {fn EXP(1)} AS e_constant`

returns 2.718281828...

The following Embedded SQL example returns the exponential values for the integers 0 through 10:

```   SET a=0
WHILE a<11 {
&sql(SELECT {fn EXP(:a)} INTO :b)
IF SQLCODE'=0 {
WRITE !,"Error code ",SQLCODE
QUIT }
ELSE {
WRITE !,"Exponential of ",a," = ",b
SET a=a+1 }
}```

The following Embedded SQL example demonstrates that EXP is the inverse of LOG:

```  SET x=7
&sql(SELECT {fn EXP(:x)} AS Exp,
{fn LOG(:x)} AS Log,
{fn EXP({fn LOG(:x)})} AS ExpOfLog
INTO :a,:b,:c)
IF SQLCODE'=0 {
WRITE !,"Error code ",SQLCODE
QUIT }
ELSE {
WRITE "Exponential of ",x," = ",a,!
WRITE "Natural log of ",x," = ",b,!
WRITE "Exp of Log of  ",x," = ",c
}
```

Note in the third function call the small discrepancy between the number input and the calculated return value. The next example shows how to handle this computational discrepancy.

The following Embedded SQL example shows the relationship between the LOG and EXP functions for the integers 1 through 10:

```   SET a=1
WHILE a<11 {
&sql(SELECT {fn LOG(:a)} INTO :b)
IF SQLCODE'=0 {
WRITE !,"Error code ",SQLCODE
QUIT }
ELSE {
WRITE !,"Logarithm of ",a," = ",b }
&sql(SELECT ROUND({fn EXP(:b)},12) INTO :c)
IF SQLCODE'=0 {
WRITE !,"Error code ",SQLCODE }
ELSE {
WRITE !,"Exponential of log ",b," = ",c
SET a=a+1 }
}```

Note that the ROUND function is needed here to correct for very small discrepancies caused by system calculation limitations. In the above example, ROUND is set arbitrarily to 12 decimal digits for this purpose.

Feedback