Implementation:Google deepmind Mujoco MjTnum Header
| Knowledge Sources | |
|---|---|
| Domains | C API, Numeric Types, Precision Configuration, Type Definitions |
| Last Updated | 2026-02-15 04:00 GMT |
Overview
Compact C header file that defines MuJoCo's fundamental numeric type (mjtNum) with compile-time single/double precision selection, byte type, and size type.
Description
mjtnum.h is a minimal 46-line header that establishes the core numeric types used throughout MuJoCo. By default, mjtNum is typedef'd to double with mjMINVAL set to 1E-15 for denominator safety. When mjUSESINGLE is defined at compile time, mjtNum becomes float with mjMINVAL as 1E-15f. The header also defines mjtByte (unsigned char, used for boolean flags) and mjtSize (int64_t, used for buffer sizes). These three types form the numeric foundation that all other MuJoCo headers and computation code depend on.
Usage
This header is included by mjmodel.h and transitively by all MuJoCo code. It is used whenever MuJoCo's floating-point precision needs to be configurable between single and double precision at compile time. The mjtByte type is used for boolean arrays in model data, and mjtSize is used for memory allocation sizes.
Code Reference
Source Location
- Repository: Google_deepmind_Mujoco
- File: include/mujoco/mjtnum.h
- Lines: 1-46
Key Functions
// Floating-point type with compile-time precision selection
#ifndef mjUSESINGLE
typedef double mjtNum;
#define mjMINVAL 1E-15 // minimum value in any denominator
#else
typedef float mjtNum;
#define mjMINVAL 1E-15f
#endif
// Byte type for boolean flags
typedef unsigned char mjtByte; // used for true/false
// Size type for buffer allocation
typedef int64_t mjtSize; // used for buffer sizes
Import
#include <mujoco/mjtnum.h>
I/O Contract
Inputs
| Name | Type | Required | Description |
|---|---|---|---|
| mjUSESINGLE | preprocessor define | No | If defined, switches mjtNum from double to float precision |
Outputs
| Name | Type | Description |
|---|---|---|
| mjtNum | typedef (double or float) | Primary floating-point type used for all MuJoCo numerical computations |
| mjMINVAL | #define (1E-15 or 1E-15f) | Minimum safe denominator value to prevent division by zero |
| mjtByte | typedef (unsigned char) | Byte-sized type used for boolean flag arrays |
| mjtSize | typedef (int64_t) | 64-bit integer type used for buffer and memory sizes |
Related Pages
- Google_deepmind_Mujoco_MjModel_Header - Primary consumer of mjtNum; includes this header
- Google_deepmind_Mujoco_MjSpec_Header - Model specification header that includes mjtnum.h
- Google_deepmind_Mujoco_MjThread_Header - Threading header in the same include directory