- 
					
						首页
					
				
 
				- 
					
						C4D R23.110 C++ SDK
					
				
 
			
			
				
				
					
						Basic Data Types
					
					
						
							内容表
						
						
						
							
							关于
						
						
							The
							
								MAXON API
							
							defines multiple primitive mathematical data types. These data types are the building blocks for more complex data types.
						
						
							- 
								注意
							
 
							- 
								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.
						
					 
				 
				
					maxon::Data
				
				data;
				data.
				
					Set
				
				(
				
					maxon::Bool
				
				(
				
					true
				
				))
				
					iferr_return
				
				;
			
 
		 
		
			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.
maxon::Data
data;
data.
Set
(
maxon::Int64
(123))
iferr_return
;
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.
- 
注意
 
- 
For bigger integer values use
maxon::BigInteger
.
 
Float
Floating point data types are available in 32 and 64 bit size:
- 
注意
 
- 
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.
maxon::Data
data;
data.
Set
(
maxon::Float32
(123.4))
iferr_return
;
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
if
(
maxon::CompareFloatTolerant
(sum, c))
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.
另请参阅
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.
static
maxon::Result<void>
GetMinMax(
maxon::BaseArray<maxon::Int>
* values,
maxon::Int
& min,
maxon::Int
& max)
{
if
(!values)
return
maxon::NullptrError(
MAXON_SOURCE_LOCATION
);
min =
maxon::LIMIT<maxon::Int>::MAX
;
max =
maxon::LIMIT<maxon::Int>::MIN
;
for
(
const
maxon::Int
& value :* values)
{
if
(value < min)
min = value;
if
(value > max)
max = value;
}
return
maxon::OK
;
}
延伸阅读
float Float32
32 bit floating point value (float)
定义:
apibase.h:178
 
return OK
定义:
apibase.h:2532
 
int64_t Int64
64 bit signed integer datatype.
定义:
apibase.h:174
 
bool Bool
boolean type, possible values are only false/true, 8 bit
定义:
apibase.h:177
 
#define iferr_return
定义:
resultbase.h:1434
 
#define MAXON_SOURCE_LOCATION
定义:
memoryallocationbase.h:66
 
Result< typename std::conditional< GetCollectionKind< T >::value==COLLECTION_KIND::ARRAY, T, typename ByValueParam< T >::type >::type > Get() const
定义:
datatypebase.h:1352
 
Float64 Float
定义:
apibase.h:193
 
Result< void > Set(T &&data)
定义:
datatypebase.h:1341
 
#define DiagnosticOutput(formatString,...)
定义:
debugdiagnostics.h:166
 
Bool CompareFloatTolerant(Float32 a, Float32 b)
 
int32_t Int32
32 bit signed integer datatype.
定义:
apibase.h:172
 
Int64 Int
signed 32/64 bit int, size depends on the platform
定义:
apibase.h:184