Blitz3D+ Command Reference

Exp# ( float# )

Parameters

float - the power to raise e to

Description

Returns e raised to the given power, where e is about 2.71828.

Exp is the inverse of Log: Log( Exp( x ) ) gives x back. It grows very fast in the positive direction and shrinks towards zero in the negative direction, never quite reaching it.

In games the useful shape is the decay curve Exp( -k*t ). It gives you natural-feeling fades and falloffs: a light that dims with distance, a camera that eases towards its target, a health regeneration rate that slows as you approach full, or fog that thickens smoothly instead of snapping on. Raising k makes the curve fall away faster.

Big positive inputs overflow quickly - Exp( 100 ) is already an astronomical number - so keep exponents small or clamp them.

See also: Log, Log10, Sqr.

Example

; Exp Example
; -----------

; Exp(x) raises e (2.71828...) to the power x: growth for positive x,
; decay for negative x. Log() is its inverse.

Print "Exp(0)  = "+Exp(0)
Print "Exp(1)  = "+Exp(1)+"  (this is e itself)"
Print "Exp(2)  = "+Exp(2)
Print "Exp(-1) = "+Exp(-1)

Print ""

; Exponential decay gives natural damage falloff: full damage up
; close, fading smoothly with distance but never quite reaching zero
Print "Explosion damage at increasing distance:"
For dist=0 To 50 Step 10
    damage#=100*Exp(-dist/15.0)
    Print RSet(dist,4)+"m : "+Int(damage)+" damage"
Next

Print ""
Print "Press any key to close the example"
WaitKey

End

Index