Basic Data Types

About

The MAXON API defines multiple primitive mathematical data types. These data types are the building blocks for more complex data types.

Note
These data types should be used instead of the standard C++ data types.

Bool

maxon::Bool stores a Boolean value.

// This example stores and receives a Boolean value in a maxon::Data container.
const maxon::Bool boolean = data.Get<maxon::Bool>() iferr_return;
DiagnosticOutput("Boolean Value: @", boolean);
if (boolean)
DiagnosticOutput("Value is \"true\".");
Definition: datatypebase.h:1199
Result< void > Set(T &&data)
Definition: datatypebase.h:1393
Result< typename std::conditional< GetCollectionKind< T >::value==COLLECTION_KIND::ARRAY, T, typename ByValueParam< T >::type >::type > Get() const
Definition: datatypebase.h:1404
bool Bool
boolean type, possible values are only false/true, 8 bit
Definition: apibase.h:181
#define DiagnosticOutput(formatString,...)
Definition: debugdiagnostics.h:176
#define iferr_return
Definition: resultbase.h:1465

Int

Different integer type of the sizes 16, 32 and 64 bit are defined:

// This example stores and receives an integer value in a maxon::Data container.
const maxon::Int64 integer = data.Get<maxon::Int64>() iferr_return;
DiagnosticOutput("Integer Value: @", integer);
int64_t Int64
64 bit signed integer datatype.
Definition: apibase.h:178

If such a integer value should be converted to a floating point value one must consider the limits of such conversion. Values outside that limit will result in an overflow.

Note
For bigger integer values use maxon::BigInteger.

Float

Floating point data types are available in 32 and 64 bit size:

Note
A number can also be cast into a maxon::Float using the "_f" operator.
// This example stores and receives a float value in a maxon::Data container.
const maxon::Float32 floataValue = data.Get<maxon::Float32>() iferr_return;
DiagnosticOutput("Float Value: @", floataValue);
float Float32
32 bit floating point value (float)
Definition: apibase.h:182

Floating point data is a complex data type that could be corrupted.

Two floating point values (that are not exactly zero) should not be compared with "==".

// This example compares two floating point values.
const maxon::Float a = 0.35;
const maxon::Float b = 0.15;
const maxon::Float c = 0.5;
const maxon::Float sum = a + b;
// this may or may not work
if (sum == c)
DiagnosticOutput("Vales are the same.");
// this will work
DiagnosticOutput("Vales are the same.");
Py_UNICODE c
Definition: unicodeobject.h:1200
Float64 Float
Definition: apibase.h:197
Bool CompareFloatTolerant(Float32 a, Float32 b)

Different floating point data types have different minimum and maximum values:

Multiplying two float values could result in an overflow. These constants define safe ranges that can be used without the risk of such an overflow.

When a floating point value is converted into another scalar value it could easily exceed the range of valid values of the target type. A safe conversation is done with:

// This example converts a floating point result safely to a integer result.
const maxon::Int32 range = 1000;
const maxon::Float percentage = 0.15;
const maxon::Float res = percentage * maxon::Float(range);
const maxon::Int32 intRes = maxon::SafeConvert<maxon::Int32>(res);
Py_UCS4 * res
Definition: unicodeobject.h:1113
int32_t Int32
32 bit signed integer datatype.
Definition: apibase.h:176

Char

A character is a single symbol.

See also String Manual.

Limit

The Limit template class defines the minimum and maximum vale a given scalar type can store. An example is maxon::LIMIT<maxon::Int64>:

  • maxon::LIMIT<maxon::Int64>::MIN: The minimum value of the data type.
  • maxon::LIMIT<maxon::Int64>::MAX: The maximum value of the data type.
// This example function searches the minimum and maximum value stored in the given maxon::BaseArray.
// To compare a stored value the reference values are initialized with LIMIT<>::MIN and LIMIT<>::MAX.
{
if (!values)
return maxon::NullptrError(MAXON_SOURCE_LOCATION);
for (const maxon::Int& value :* values)
{
if (value < min)
if (value > max)
}
return maxon::OK;
}
PyObject * value
Definition: abstract.h:715
Definition: basearray.h:412
Definition: apibasemath.h:54
Int64 Int
signed 32/64 bit int, size depends on the platform
Definition: apibase.h:188
return OK
Definition: apibase.h:2667
#define MAXON_SOURCE_LOCATION
Definition: memoryallocationbase.h:67
const char Py_ssize_t const char Py_ssize_t Py_ssize_t max
Definition: modsupport.h:59
const char Py_ssize_t const char Py_ssize_t min
Definition: modsupport.h:58

Further Reading