expm1 — Compute exp(X) - 1 elementwise with near-zero accuracy.
Y = expm1(X) evaluates the natural exponential minus one for every element of a real or complex array. Its dedicated numerical path retains accuracy when X is close to zero.
Syntax
Y = expm1(X)Inputs
X- Type
Any- Required
- Yes
- Description
- Single or double real/complex input; integer, logical, and character forms are RunMat-only extensions.
Returns
Y- Type
NumericArray- Description
- Elementwise exp(X)-1 result with the input floating-point class and shape.
Errors
RunMat:expm1:InvalidInput- When
- Input cannot be interpreted as numeric, logical, character, or complex data.
- Message
expm1: invalid input
RunMat:expm1:Internal- When
- Internal tensor construction or provider interaction fails.
- Message
expm1: internal error
Behavior
Y = expm1(X) evaluates exp(X) - 1 elementwise without the cancellation that direct subtraction introduces near zero. It preserves the shape and the single or double precision of real and complex floating-point input.
Complex input uses the principal complex exponential before subtracting one. Sparse floating-point input remains sparse because each implicit zero maps back to zero. Table and timetable input is mapped variable by variable only when each variable supports expm1.
Fixed-width integer, logical, and character inputs are separate RunMat extensions. They produce double output and MATLAB compatibility mode rejects each extension with its corresponding structured compatibility error.
Integer extension inputs must lie in the inclusive interval [-2^53, 2^53]. RunMat rejects a wider integer before conversion rather than silently rounding it at the binary64 boundary.
GPU execution
Real floating-point tensors can remain on the owning provider through its precise unary expm1 operation. Complex values and providers that explicitly report an unsupported operation use an owner-aware host fallback; other provider failures remain errors.
expm1 is not fused until the fusion ABI can retain its near-zero accuracy. Replacing it with the expression exp(X) - 1 would change the documented numerical contract.
Examples
Retain accuracy for a tiny growth rate
x = 1e-12;
y = expm1(x)Expected output:
y = 1.0000000000005e-12Convert growth rates into relative factors
rates = [-0.10 -0.05 0 0.05 0.10];
factors = expm1(rates)Expected output:
factors = [-0.0952 -0.0488 0 0.0513 0.1052]Apply expm1 to provider-resident data
G = gpuArray(linspace(-1, 1, 5));
result = expm1(G);
out = gather(result)Expected output:
out = [-0.6321 -0.3935 0 0.6487 1.7183]Use expm1 with complex values
z = [1+1i, -1+pi*1i];
w = expm1(z)Expected output:
w = [0.4687 + 2.2874i, -1.3679 + 0.0000i]Evaluate character code points in RunMat mode
C = 'ABC';
Y = expm1(C)Expected output:
Y = [1.6949e+28 4.6072e+28 1.2524e+29]Using expm1 with coding agents
Open a RunMat example with live inputs, then ask the agent to explain how expm1 changes the result.
Run a small expm1 example, explain the result, then change one input and compare the output.
FAQ
When should I prefer expm1 over exp(X) - 1?⌄
Use expm1 whenever values can be close to zero. It avoids the significant-digit loss caused by subtracting one from a result close to one.
Does expm1 preserve shape?⌄
Yes. The result has the same shape as the input.
How are logical arrays handled?⌄
Logical arrays convert to double only in RunMat compatibility mode. MATLAB compatibility mode rejects that extension.
What happens with complex input?⌄
Complex values use the principal complex exponential and subtract one from the real component of the result.
What happens when a provider lacks its expm1 operation?⌄
RunMat gathers through the owning provider and computes the same result on the host. It restores the result only when the provider supports the required precision.
Which precision does expm1 return?⌄
Single input returns single and double input returns double. Integer, logical, and character extension forms return double.
Why is expm1 not fused?⌄
The current fusion expression would evaluate exp(X) - 1 and lose the accuracy that defines expm1. Direct provider execution uses the precise operation instead.
Related Math functions
Elementwise
abs · angle · besselj · bsxfun · complex · conj · double · eps · erf · erfcinv · exp · flintmax · gamma · gammaln · heaviside · hypot · imag · int16 · int32 · int64 · int8 · intmax · intmin · ldivide · log · log10 · log1p · log2 · minus · nextpow2 · plus · pow2 · power · rdivide · real · realmax · realmin · realsqrt · rescale · sign · single · sqrt · times · typecast · uint16 · uint32 · uint64 · uint8
Optim
acceptancesa · annealingboltz · annealingfast · coneprog · crossoverarithmetic · crossoverheuristic · crossoverintermediate · crossoverlaplace · crossoverscattered · crossoversinglepoint · crossovertwopoint · eqnproblem · EquationProblem.solve · EquationProblem.subsasgn · EquationProblem.subsref · evaluate · fgoalattain · fitscalingprop · fitscalingrank · fitscalingshiftlinear · fitscalingtop · fminbnd · fmincon · fminimax · fminsearch · fminunc · fseminf · fsolve · fzero · ga · gacreationlinearfeasible · gacreationnonlinearfeasible · gacreationsobol · gacreationuniform · gacreationuniformint · gaplotbestf · gaplotbestindiv · gaplotdistance · gaplotexpectation · gaplotgenealogy · gaplotmaxconstr · gaplotrange · gaplotscorediversity · gaplotscores · gaplotselection · gaplotstopping · integerConstraint · integral · intlinprog · linprog · lsqcurvefit · lsqlin · LsqlinWarmStart.subsasgn · LsqlinWarmStart.subsref · lsqnonlin · lsqnonneg · mutationadaptfeasible · mutationgaussian · mutationpositivebasis · mutationpower · mutationuniform · optimexpr · optimget · OptimizationConstraint.evaluate · OptimizationConstraint.subsasgn · OptimizationConstraint.subsref · OptimizationExitflag.double · OptimizationExitflag.eq · OptimizationExitflag.ne · OptimizationExitflag.string · OptimizationExpression.acos · OptimizationExpression.acosh · OptimizationExpression.acot · OptimizationExpression.acoth · OptimizationExpression.acsc · OptimizationExpression.acsch · OptimizationExpression.asec · OptimizationExpression.asech · OptimizationExpression.asin · OptimizationExpression.asinh · OptimizationExpression.atan · OptimizationExpression.atanh · OptimizationExpression.cat · OptimizationExpression.cos · OptimizationExpression.cosh · OptimizationExpression.cot · OptimizationExpression.coth · OptimizationExpression.csc · OptimizationExpression.csch · OptimizationExpression.ctranspose · OptimizationExpression.cumprod · OptimizationExpression.cumsum · OptimizationExpression.diag · OptimizationExpression.diff · OptimizationExpression.dot · OptimizationExpression.eq · OptimizationExpression.evaluate · OptimizationExpression.exp · OptimizationExpression.ge · OptimizationExpression.horzcat · OptimizationExpression.ldivide · OptimizationExpression.le · OptimizationExpression.log · OptimizationExpression.mean · OptimizationExpression.minus · OptimizationExpression.mldivide · OptimizationExpression.mpower · OptimizationExpression.mrdivide · OptimizationExpression.mtimes · OptimizationExpression.norm · OptimizationExpression.plus · OptimizationExpression.power · OptimizationExpression.prod · OptimizationExpression.rdivide · OptimizationExpression.reshape · OptimizationExpression.sec · OptimizationExpression.sech · OptimizationExpression.sin · OptimizationExpression.sinh · OptimizationExpression.sqrt · OptimizationExpression.subsasgn · OptimizationExpression.subsref · OptimizationExpression.sum · OptimizationExpression.tan · OptimizationExpression.tanh · OptimizationExpression.times · OptimizationExpression.trace · OptimizationExpression.transpose · OptimizationExpression.uminus · OptimizationExpression.uplus · OptimizationExpression.vertcat · OptimizationExpression.zeros · OptimizationExpression.zerosLike · OptimizationProblem.solve · OptimizationProblem.subsasgn · OptimizationProblem.subsref · OptimizationVariable.subsasgn · OptimizationVariable.subsref · optimoptions · optimplotconstrviolation · optimplotfirstorderopt · optimplotfunccount · optimplotfval · optimplotfvalconstr · optimplotmilp · optimplotstepsize · optimplotx · optimproblem · optimset · optimvar · optimwarmstart · particleswarm · patternsearch · psplotbestf · psplotbestx · psplotfuncount · psplotmaxconstr · psplotmeshsize · pswcreationuniform · pswplotbestf · quad · quadprog · QuadprogWarmStart.subsasgn · QuadprogWarmStart.subsref · saplotbestf · saplotbestx · saplotf · saplotstopping · saplottemperature · saplotx · savemilpsolutions · secondordercone · selectionremainder · selectionroulette · selectionstochunif · selectiontournament · selectionuniform · simulannealbnd · solve · surrogateopt · surrogateoptplot · temperatureboltz · temperatureexp · temperaturefast
Trigonometry
acos · acosd · acosh · acotd · acscd · asecd · asin · asind · asinh · atan · atan2 · atan2d · atand · atanh · cos · cosd · cosh · cospi · deg2rad · pol2cart · rad2deg · sin · sind · sinh · sinpi · tan · tand · tanh
Reduction
all · any · bounds · cummax · cummin · cumprod · cumsum · cumtrapz · diff · gradient · max · maxk · mean · median · min · mink · movmax · movmean · movmedian · movmin · movprod · movstd · movsum · movvar · nnz · prod · rms · std · sum · trapz · var
Structure
bandwidth · isdiag · ishermitian · issymmetric · istril · istriu · symrcm
Signal
blackman · butter · buttord · cheb2ord · conv · conv2 · deconv · downsample · envelope · filter · filtfilt · fir1 · freqz · gauspuls · hamming · hann · hilbert · periodogram · pulstran · pwelch · rectpuls · resample · sawtooth · sinc · spectrogram · square · tripuls · unwrap · upsample · zplane
Factor
chol · decomposition · decomposition.ctranspose · decomposition.mldivide · decomposition.mrdivide · decomposition.mtimes · decomposition.rdivide · decomposition.subsref · decomposition.times · decomposition.uminus · decomposition.uplus · eig · eigs · gmres · ichol · ilu · lu · ordeig · ordqz · ordschur · pcg · qr · qz · rsf2csf · schur · svd
Ops
cross · ctranspose · dot · mldivide · mpower · mrdivide · mtimes · pagemtimes · pagetranspose · trace · transpose
Interpolation
griddedInterpolant · griddedInterpolant.subsref · interp1 · interp1q · interp2 · pchip · ppval · spline
Integer Division
Source you can read
Every RunMat function's source is public. Read exactly how expm1 is executed, line by line, in Rust.
- View the source for expm1 in Rust on GitHub
- Learn how the RunMat runtime works
- Found a bug? Open an issue with a minimal reproduction.
About RunMat
RunMat is a runtime that executes MATLAB-syntax code fast on any GPU. The runtime is free for individuals, including freelancers; students and faculty at an academic institution, for teaching or research there; contributors to an open-source project, for work on that project; organizations with 250 or fewer people and US$10M or less in annual revenue; and anyone, for non-production use. See runmat.com/license.
- RunMat automatically optimizes your math for GPU execution on Apple, Nvidia, and AMD hardware. No code changes needed. Simulations that took hours now take minutes.
- Start running code in seconds. RunMat runs in the browser, on the desktop, or from the CLI. No license server, no IT ticket.