Sign in Join
FPDoc Onlineexperiment

Math unit

Additional mathematical routines.

This document describes the math unit. The math unit was initially written by Florian Klaempfl. It provides mathematical functions which aren't covered by the system unit.

This chapter starts out with a definition of all types and constants that are defined, after which an overview is presented of the available functions, grouped by category, and the last part contains a complete explanation of each function.

The following things must be taken into account when using this unit:

  1. This unit is compiled in Object Pascal mode so all integers are 32 bit.
  2. Some overloaded functions exist for data arrays of integers and floats. When using the address operator (@) to pass an array of data to such a function, make sure the address is typecasted to the right type, or turn on the 'typed address operator' feature. failing to do so, will cause the compiler not be able to decide which function you want to call.

Classes and records

EInvalidArgumentclassException raised when invalid arguments are passed to a function.

Procedures and functions

ArcCosfunctionReturn inverse cosine.
ArcCosHfunctionReturn inverse hyperbolic cosine.
ArcCotfunction
ArcCotHfunction
ArcCscfunction
ArcCscHfunction
ArCosHfunctionReturn inverse hyperbolic cosine.
ArcSecfunction
ArcSecHfunction
ArcSinfunctionReturn inverse sine.
ArcSinHfunctionReturn inverse hyperbolic sine.
ArcTan2functionReturn arctangent of (y/x).
ArcTanHfunctionReturn inverse hyperbolic tangent.
ArSinHfunctionReturn inverse hyperbolic sine.
ArTanHfunctionReturn inverse hyperbolic tangent.
CeilfunctionReturn the lowest integer number greater than or equal to argument.
Ceil64functionRound to the nearest bigger int64 value.
ClearExceptionsprocedureClear Floating Point Unit exceptions.
CompareValuefunctionCompare 2 values.
CosecantfunctionCalculate cosecant.
coshfunctionReturn hyperbolic cosine.
CotfunctionAlias for Cotan.
CotanfunctionReturn cotangent.
CotHfunction
CscfunctionAlias for cosecant.
CscHfunction
CycleToDegfunction
CycleToGradfunction
CycleToRadfunctionConvert cycle angle to radians angle.
DegNormalizefunctionNormalize an angle measured in degrees.
DegToCyclefunction
DegToGradfunctionConvert degree angle to grads angle.
DegToRadfunctionConvert degree angle to radians angle.
DivModprocedureReturn DIV and MOD of arguments.
EnsureRangefunctionChange value so it fits in a specified range.
ExpM1function
FloorfunctionReturn the largest integer smaller than or equal to argument.
Floor64functionRound to the nearest smaller int64 value.
FModfunctionFloatin point modulo.
FrexpprocedureReturn mantissa and exponent.
FutureValuefunctionCalculate the future value of an investment.
GetExceptionMaskfunctionGet the Floating Point Unit exception mask.
GetPrecisionModefunctionReturn the Floating Point Unit precision mode.
GetRoundModefunctionReturn the Floating Point Unit rounding mode.
GradToCyclefunction
GradToDegfunctionConvert grads angle to degrees angle.
GradToRadfunctionConvert grads angle to radians angle.
HypotfunctionReturn hypotenuse of triangle.
IfThenfunctionReturn one of two values, depending on a boolean condition.
InRangefunctionCheck whether value is in range.
InterestRatefunctionCalculate the interest rate value of an investment.
IntPowerfunctionReturn integer power.
IsInfinitefunctionCheck whether value is infinite.
IsNanfunctionCheck whether value is Not a Number.
IsZerofunctionCheck whether value is zero.
LdexpfunctionReturn (2 to the power p) times x.
LnXP1functionReturn natural logarithm of 1+X.
Log10functionReturn 10-Based logarithm.
Log2functionReturn 2-based logarithm.
LogNfunctionReturn N-based logarithm.
MaxfunctionReturns the largest of two values.
MaxIntValuefunctionReturn largest element in integer array.
MaxValuefunctionReturn largest value in array.
MeanfunctionReturn mean value of array.
MeanAndStdDevprocedureReturn mean and standard deviation of array.
MinfunctionReturn smallest of two values.
MinIntValuefunctionReturn smallest value in integer array.
MinValuefunctionReturn smallest value in array.
modulus(Float,Float):FloatoperatorFloating point modulo.
MomentSkewKurtosisprocedureReturn 4 first moments of distribution.
NormfunctionReturn Euclidean norm.
NumberOfPeriodsfunctionCalculate the number of periods for an investment.
PaymentfunctionCalculate the payment for an investment.
PopnStdDevfunctionReturn Population standard deviation.
PopnVariancefunctionReturn population variance.
PowerfunctionReturn real power.
power(Float,Float):FloatoperatorRaise base to the power exponent.
power(Int64,Int64):Int64operatorRaise base to the power exponent.
PresentValuefunctionCalculate the present value given the future value of an investment.
RadToCyclefunctionConvert radians angle to cycle angle.
RadToDegfunctionConvert radians angle to degrees angle.
RadToGradfunctionConvert radians angle to grads angle.
RandGfunctionReturn gaussian distributed random number.
RandomFromfunctionReturn a random element of an array of numbers.
RandomRangefunctionReturn a random number in a range.
RoundTofunctionRound to the specified number of digits.
SameValuefunctionCheck whether 2 float values are the same.
SecfunctionAlias for secant.
SecantfunctionCalculate secant.
SecHfunction
SetExceptionMaskfunctionSet the Floating Point Unit exception mask.
SetPrecisionModefunctionSet the Floating Point Unit precision mode.
SetRoundModefunctionSet the Floating Point Unit rounding mode.
SignfunctionReturn sign of argument.
SimpleRoundTofunctionRound to the specified number of digits (rounding up if needed).
SinCosprocedureReturn sine and cosine of argument.
sinhfunctionReturn hyperbolic sine.
StdDevfunctionReturn standard deviation of data.
SumfunctionReturn sum of values.
SumIntfunctionReturn the sum of an array of integers.
SumOfSquaresfunctionReturn sum of squares of values.
SumsAndSquaresprocedureReturn sum and sum of squares of values.
TanfunctionReturn tangent.
tanhfunctionReturn hyperbolic tangent.
TotalVariancefunctionReturn total variance of values.
VariancefunctionReturn variance of values.

Types

FloattypeFloat type used in all calls.
PFloattypePointer to type.
PIntegertypePointer to integer type.
TFPUExceptiontypeType describing Floating Point processor exceptions.
TFPUExceptionMasktypeType to set the Floating Point Unit exception mask.
TFPUPrecisionModetypeType describing the default precision for the Floating Point processor.
TFPURoundingModetypeType describing the rounding mode for the Floating Point processor.
TPaymentTimeenumerationType used in financial (interest) calculations.
TRoundToRangetypeRange with valid range of digits in RoundTo.
TValueRelationshiptypeType to describe relational order between values.
TValueSigntypeType indicating sign of a value.

Constants

EqualsValueconstantValues are the same.
GreaterThanValueconstantFirst values is greater than second value.
InfinityconstantValue is infinity.
LessThanValueconstantFirst value is less than second value.
MaxFloatconstantMaximum value of float type.
MinFloatconstantMinimum value (closest to zero) of float type.
NaNconstantValue is Not a Number.
NegativeValueconstantValue is negative.
NegInfinityconstantValue is negative (minus) infinity.
PositiveValueconstantValue is positive.
ZeroValueconstantValue is zero.

Topics

AngleConversionRoutinestopicAngle unit conversion.
CashFlowFunctionstopicCash flow functions.
ExpLogRoutinestopicExponential and logarithmic functions.
GeometricalRoutinestopicGeometrical functions.
HyperbolicRoutinestopicHyperbolic functions.
MinMaxRoutinestopicMin/max determination.
NumberConversionRoutinestopicNumber converting.
StatisticalRoutinestopicStatistical functions.
TrigoniometricRoutinestopicTrigonometric functions.

Uses

An experiment, built from development snapshots. Not the official Free Pascal or Lazarus documentation.