Basic Data Types

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\".");

# 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);

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);

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.");

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);

# Char

A character is a single symbol.

# 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)
min = value;
if (value > max)
max = value;
}
return maxon::OK;
}

maxon::Float32
float Float32
32 bit floating point value (float)
Definition: apibase.h:178
maxon::Data
Definition: datatypebase.h:1143
maxon::OK
return OK
Definition: apibase.h:2532
maxon::Int64
int64_t Int64
64 bit signed integer datatype.
Definition: apibase.h:174
maxon::Bool
bool Bool
boolean type, possible values are only false/true, 8 bit
Definition: apibase.h:177
iferr_return
#define iferr_return
Definition: resultbase.h:1434
MAXON_SOURCE_LOCATION
#define MAXON_SOURCE_LOCATION
Definition: memoryallocationbase.h:66
maxon::Data::Get
Result< typename std::conditional< GetCollectionKind< T >::value==COLLECTION_KIND::ARRAY, T, typename ByValueParam< T >::type >::type > Get() const
Definition: datatypebase.h:1352
maxon::Float
Float64 Float
Definition: apibase.h:193
maxon::Data::Set
Result< void > Set(T &&data)
Definition: datatypebase.h:1341
maxon::BaseArray
Definition: basearray.h:366
DiagnosticOutput
#define DiagnosticOutput(formatString,...)
Definition: debugdiagnostics.h:166
maxon::Result< void >
maxon::CompareFloatTolerant
Bool CompareFloatTolerant(Float32 a, Float32 b)
maxon::Int32
int32_t Int32
32 bit signed integer datatype.
Definition: apibase.h:172
maxon::Int
Int64 Int
signed 32/64 bit int, size depends on the platform
Definition: apibase.h:184
maxon::LIMIT
Definition: apibasemath.h:53