Mathematical Functions

内容表

关于

The MAXON API contains mathematical constants and functions that can be used with the basic data types. These constants and functions are defined in the general_math.h and lib_math.h header files. See also Basic Data Types .

常量

Generic constants are:

注意
If an error occurs in a function, this function should return a proper error object. See Error Handling .

Mathematical floating point constants are:

For values and limits of data types see Basic Data Types .

// This example calculates the area of a circle of the given radius.
const maxon::Float radius = 123.0; const maxon::Float area = maxon::PI * maxon::Sqr (radius);

Template Functions

These template functions can be used with any data type that supports the required operations:

// This example template function clamps the given values and returned a mixed result. // It uses template sub-functions. template < typename T> static T ClampAndBlend(T a, T b, T min, T max, T blend) { a = maxon::ClampValue (a, min, max); b = maxon::ClampValue (b, min, max); return maxon::Blend (a, b, blend); }

Exponent

These exponential functions are available for maxon::Float32 and maxon::Float64 values:

Trigonometry

These trigonometric functions are available for maxon::Float32 and maxon::Float64 values:

// This example calculates coordinates along a circle. const maxon::Int count = 100; const maxon::Float countF = maxon::Float (count); const maxon::Float step = maxon::PI2 / countF; maxon::Float angle = 0.0; for ( maxon::Int i = 0; i < count; ++i) { maxon::Float sin; maxon::Float cos; maxon::SinCos (angle, sin, cos); const maxon::Float degree = maxon::RadToDeg (angle);

// output const maxon::String result = FormatString ( "Pos X: @, Y: @, at @ degree." , sin, cos, degree); DiagnosticOutput (result);

// next angle angle += step; }

Advanced functions are:

Limit

These functions are available for maxon::Float32 and maxon::Float64 values:

// This example calculates the previous and following integer numbers for the given float value. const maxon::Float value = 1.23; const maxon::Float previousInt = maxon::Floor (value); const maxon::Float nextInt = maxon::Ceil (value);

Iterables

These template functions work with all values stored in the given iterable e.g. a maxon::BaseArray :

BaseArray Manual and Arrays Manual .

// This example gets the sum and average value of all elements stored in the BaseArray. maxon::BaseArray<maxon::Float> baseArray; baseArray. Append (1.0) iferr_return ; baseArray. Append (2.0) iferr_return ; baseArray. Append (3.0) iferr_return ; const maxon::Float sum = maxon::GetSum (baseArray); const maxon::Float average = maxon::GetAverage (baseArray);

杂项

These mathematical utility functions are available for maxon::Float32 and maxon::Float64 values:

Special maxon::UInt functions are:

This modulo operation is defined for maxon::Int32 , maxon::Int64 , maxon::Float32 and maxon::Float64 .

延伸阅读

maxon::PI2
static constexpr Float64 PI2
floating point constant: 2.0 * PI
定义: apibasemath.h:145
maxon::GetAverage
MAXON_ATTRIBUTE_FORCE_INLINE std::remove_reference< ITERABLETYPE >::type::ValueType GetAverage(ITERABLETYPE &&array)
Returns the average of all elements.
定义: lib_math.h:300
maxon::ClampValue
MAXON_ATTRIBUTE_FORCE_INLINE X ClampValue(X value, X lowerLimit, X upperLimit)
Clips a value against a lower and upper limit. The new value is returned.
定义: apibasemath.h:358
maxon::Blend
MAXON_ATTRIBUTE_FORCE_INLINE X Blend(const X &value1, const X &value2, Y blendValue)
Blends two values. If blendValue is 0.0 value1 is returned, if blendValue is 1.0 value2 is returned....
定义: apibasemath.h:365
maxon::String
定义: string.h:1197
maxon::SinCos
MAXON_ATTRIBUTE_FORCE_INLINE void SinCos(Float32 val, Float32 &sn, Float32 &cs)
Calculates both sine and cosine of a value.
定义: apibasemath.h:481
iferr_return
#define iferr_return
定义: resultbase.h:1434
maxon::Float
Float64 Float
定义: apibase.h:193
maxon::BaseArray
定义: basearray.h:366
DiagnosticOutput
#define DiagnosticOutput(formatString,...)
定义: debugdiagnostics.h:166
maxon::PI
static constexpr Float64 PI
floating point constant: PI
定义: apibasemath.h:139
maxon::GetSum
MAXON_ATTRIBUTE_FORCE_INLINE std::remove_reference< ITERABLETYPE >::type::ValueType GetSum(ITERABLETYPE &&array)
Returns the sum of all elements.
定义: lib_math.h:287
maxon::BaseArray::Append
MAXON_ATTRIBUTE_FORCE_INLINE ResultRef< T > Append()
定义: basearray.h:569
maxon::Int
Int64 Int
signed 32/64 bit int, size depends on the platform
定义: apibase.h:184
maxon::Ceil
MAXON_ATTRIBUTE_FORCE_INLINE Float32 Ceil(Float32 val)
Rounds to the smallest following integer number.
定义: apibasemath.h:278
FormatString
#define FormatString(...)
定义: string.h:2031
maxon::Floor
MAXON_ATTRIBUTE_FORCE_INLINE Float32 Floor(Float32 val)
Rounds to the largest previous integer number.
定义: apibasemath.h:272
maxon::Sqr
MAXON_ATTRIBUTE_FORCE_INLINE X Sqr(X a, X b)
Calculates square difference of two values.
定义: apibasemath.h:368
maxon::RadToDeg
MAXON_ATTRIBUTE_FORCE_INLINE Float32 RadToDeg(Float32 r)
Converts float value from radians to degrees.
定义: apibasemath.h:475

Copyright  © 2014-2025 乐数软件    

工业和信息化部: 粤ICP备14079481号-1