Math Engine Reference: Quantity
문서 탐색
개요
@file math_engine_quantity.h Allocation-free quantity, engineering constant catalog and text C ABI.
Binary 값은 유한값만 허용하고 fixed decimal의 scale은 0..18이다. 모든 단위와 문자열 변환은 locale 독립이며, 함수 출력은 성공한 뒤에만 commit된다. Precision decimal을 사용하는 호출은 request가 가리키는 caller-owned context를 직렬화해야 한다.
- 실행 원본:
include/math_engine/math_engine_quantity.h - 분류: 단위·수량
관련 public header
공개 API
Header 사용 시작
이 module의 public declaration을 사용하려면 installed SDK의 다음 header를 include한다.
#include <math_engine/math_engine_quantity.h>
Type과 callback
math_engine_quantity_numeric_kind_t
Quantity가 값을 저장하는 numeric backend 식별자다.
typedef enum math_engine_quantity_numeric_kind {
MATH_ENGINE_QUANTITY_NUMERIC_INVALID = 0, /**< 활성 numeric storage가 없는 zero/sentinel kind다. */
MATH_ENGINE_QUANTITY_NUMERIC_BINARY32 = 1, /**< 유한 IEEE-754 binary32 값을 =numeric.binary32=에 저장한다. */
MATH_ENGINE_QUANTITY_NUMERIC_BINARY64 = 2, /**< 유한 IEEE-754 binary64 값을 =numeric.binary64=에 저장한다. */
MATH_ENGINE_QUANTITY_NUMERIC_FIXED_DECIMAL = 3, /**< =coefficient*10^-scale= exact decimal을 저장한다. */
MATH_ENGINE_QUANTITY_NUMERIC_PRECISION_DECIMAL = 4 /**< Caller precision context의 live slot을 pointer-free 참조한다. */
} math_engine_quantity_numeric_kind_t;
math_engine_quantity_numeric_kind_t.MATH_ENGINE_QUANTITY_NUMERIC_INVALID
활성 numeric storage가 없는 zero/sentinel kind다.
MATH_ENGINE_QUANTITY_NUMERIC_INVALID = 0,
math_engine_quantity_numeric_kind_t.MATH_ENGINE_QUANTITY_NUMERIC_BINARY32
유한 IEEE-754 binary32 값을
numeric.binary32에 저장한다.MATH_ENGINE_QUANTITY_NUMERIC_BINARY32 = 1,
math_engine_quantity_numeric_kind_t.MATH_ENGINE_QUANTITY_NUMERIC_BINARY64
유한 IEEE-754 binary64 값을
numeric.binary64에 저장한다.MATH_ENGINE_QUANTITY_NUMERIC_BINARY64 = 2,
math_engine_quantity_numeric_kind_t.MATH_ENGINE_QUANTITY_NUMERIC_FIXED_DECIMAL
coefficient*10^-scaleexact decimal을 저장한다.MATH_ENGINE_QUANTITY_NUMERIC_FIXED_DECIMAL = 3,
math_engine_quantity_numeric_kind_t.MATH_ENGINE_QUANTITY_NUMERIC_PRECISION_DECIMAL
Caller precision context의 live slot을 pointer-free 참조한다.
MATH_ENGINE_QUANTITY_NUMERIC_PRECISION_DECIMAL = 4,
math_engine_quantity_operation_t
감사 가능한 quantity 결과에 기록되는 연산 식별자다.
typedef enum math_engine_quantity_operation {
MATH_ENGINE_QUANTITY_OPERATION_INVALID = 0, /**< 완료된 quantity operation이 없는 zero/sentinel 값이다. */
MATH_ENGINE_QUANTITY_OPERATION_CONVERT_UNIT = 1, /**< 차원을 유지하며 호환 target unit으로 값을 변환했다. */
MATH_ENGINE_QUANTITY_OPERATION_CONVERT_NUMERIC = 2, /**< Unit을 유지하며 numeric backend를 변환했다. */
MATH_ENGINE_QUANTITY_OPERATION_ADD = 3, /**< 호환 차원의 =lhs+rhs=를 계산했다. */
MATH_ENGINE_QUANTITY_OPERATION_SUBTRACT = 4, /**< 호환 차원의 =lhs-rhs=를 계산했다. */
MATH_ENGINE_QUANTITY_OPERATION_MULTIPLY = 5, /**< 값과 unit dimension을 곱했다. */
MATH_ENGINE_QUANTITY_OPERATION_DIVIDE = 6, /**< 값과 unit dimension을 =lhs/rhs=로 나눴다. */
MATH_ENGINE_QUANTITY_OPERATION_POWER = 7, /**< =lhs^request.power= 정수 거듭제곱을 계산했다. */
MATH_ENGINE_QUANTITY_OPERATION_PARSE = 8 /**< ASCII number와 unit expression을 quantity로 해석했다. */
} math_engine_quantity_operation_t;
math_engine_quantity_operation_t.MATH_ENGINE_QUANTITY_OPERATION_INVALID
완료된 quantity operation이 없는 zero/sentinel 값이다.
MATH_ENGINE_QUANTITY_OPERATION_INVALID = 0,
math_engine_quantity_operation_t.MATH_ENGINE_QUANTITY_OPERATION_CONVERT_UNIT
차원을 유지하며 호환 target unit으로 값을 변환했다.
MATH_ENGINE_QUANTITY_OPERATION_CONVERT_UNIT = 1,
math_engine_quantity_operation_t.MATH_ENGINE_QUANTITY_OPERATION_CONVERT_NUMERIC
Unit을 유지하며 numeric backend를 변환했다.
MATH_ENGINE_QUANTITY_OPERATION_CONVERT_NUMERIC = 2,
math_engine_quantity_operation_t.MATH_ENGINE_QUANTITY_OPERATION_ADD
호환 차원의
lhs+rhs를 계산했다.MATH_ENGINE_QUANTITY_OPERATION_ADD = 3,
math_engine_quantity_operation_t.MATH_ENGINE_QUANTITY_OPERATION_SUBTRACT
호환 차원의
lhs-rhs를 계산했다.MATH_ENGINE_QUANTITY_OPERATION_SUBTRACT = 4,
math_engine_quantity_operation_t.MATH_ENGINE_QUANTITY_OPERATION_MULTIPLY
값과 unit dimension을 곱했다.
MATH_ENGINE_QUANTITY_OPERATION_MULTIPLY = 5,
math_engine_quantity_operation_t.MATH_ENGINE_QUANTITY_OPERATION_DIVIDE
값과 unit dimension을
lhs/rhs로 나눴다.MATH_ENGINE_QUANTITY_OPERATION_DIVIDE = 6,
math_engine_quantity_operation_t.MATH_ENGINE_QUANTITY_OPERATION_POWER
lhs^request.power정수 거듭제곱을 계산했다.MATH_ENGINE_QUANTITY_OPERATION_POWER = 7,
math_engine_quantity_operation_t.MATH_ENGINE_QUANTITY_OPERATION_PARSE
ASCII number와 unit expression을 quantity로 해석했다.
MATH_ENGINE_QUANTITY_OPERATION_PARSE = 8,
math_engine_quantity_fixed_value_t
Finance component와 독립적인 coefficient * 10^-scale fixed decimal 저장값이다.
typedef struct math_engine_quantity_fixed_value {
int64_t coefficient; /**< Signed exact integer 계수이며 저장값은 =coefficient*10^-scale=이다. */
int32_t scale; /**< Decimal 소수 자릿수인 포함 범위 0..18이다. */
uint32_t reserved; /**< Producer는 0으로 두며 quantity validator가 nonzero를 거부하는 ABI slot이다. */
} math_engine_quantity_fixed_value_t;
math_engine_quantity_fixed_value_t.coefficient
Signed exact integer 계수이며 저장값은
coefficient*10^-scale이다.int64_t coefficient;
math_engine_quantity_fixed_value_t.scale
Decimal 소수 자릿수인 포함 범위 0..18이다.
int32_t scale;
math_engine_quantity_fixed_value_t.reserved
Producer는 0으로 두며 quantity validator가 nonzero를 거부하는 ABI slot이다.
uint32_t reserved;
math_engine_quantity_precision_ref_t
Precision-decimal context의 slot을 가리키는 pointer-free 참조다.
typedef struct math_engine_quantity_precision_ref {
uint64_t context_id; /**< Slot을 소유한 precision context의 nonzero stable runtime ID다. */
uint32_t slot; /**< Context slot 배열의 zero-based index이며 실제 범위는 context가 검증한다. */
uint32_t generation; /**< 해제·재획득된 stale slot을 구분하는 nonzero generation token이다. */
} math_engine_quantity_precision_ref_t;
math_engine_quantity_precision_ref_t.context_id
Slot을 소유한 precision context의 nonzero stable runtime ID다.
uint64_t context_id;
math_engine_quantity_precision_ref_t.slot
Context slot 배열의 zero-based index이며 실제 범위는 context가 검증한다.
uint32_t slot;
math_engine_quantity_precision_ref_t.generation
해제·재획득된 stale slot을 구분하는 nonzero generation token이다.
uint32_t generation;
math_engine_quantity_numeric_storage_t
선택한 numeric kind 하나를 저장하는 pointer-free union이다.
typedef union math_engine_quantity_numeric_storage {
float binary32; /**< Numeric kind BINARY32에서만 의미 있는 finite 값이다. */
double binary64; /**< Numeric kind BINARY64에서만 의미 있는 finite 값이다. */
math_engine_quantity_fixed_value_t fixed_decimal; /**< FIXED_DECIMAL kind의 coefficient/scale 저장 member다. */
math_engine_quantity_precision_ref_t precision_decimal; /**< PRECISION_DECIMAL kind의 caller-context slot 참조다. */
uint64_t reserved[2]; /**< Union을 16 byte로 고정하는 ABI view이며 producer는 활성 member 기록 전 전체를 0으로 초기화한다. */
#ifdef __cplusplus
constexpr math_engine_quantity_numeric_storage() : reserved{0u, 0u} {}
constexpr explicit math_engine_quantity_numeric_storage(double value)
: binary64(value) {}
#endif
} math_engine_quantity_numeric_storage_t;
math_engine_quantity_numeric_storage_t.binary32
Numeric kind BINARY32에서만 의미 있는 finite 값이다.
float binary32;
math_engine_quantity_numeric_storage_t.binary64
Numeric kind BINARY64에서만 의미 있는 finite 값이다.
double binary64;
math_engine_quantity_numeric_storage_t.fixed_decimal
FIXED_DECIMAL kind의 coefficient/scale 저장 member다.
math_engine_quantity_fixed_value_t fixed_decimal;
math_engine_quantity_numeric_storage_t.precision_decimal
PRECISION_DECIMAL kind의 caller-context slot 참조다.
math_engine_quantity_precision_ref_t precision_decimal;
math_engine_quantity_numeric_storage_t.reserved
Union을 16 byte로 고정하는 ABI view이며 producer는 활성 member 기록 전 전체를 0으로 초기화한다.
uint64_t reserved[2];
math_engine_quantity_t
Versioned value and explicit result unit.
typedef struct math_engine_quantity {
uint32_t struct_size; /**< Exact ABI byte 크기 =sizeof(math_engine_quantity_t)=다. */
uint32_t struct_version; /**< =MATH_ENGINE_QUANTITY_VERSION_1=이어야 한다. */
uint32_t numeric_kind; /**< =numeric=에서 활성인 =math_engine_quantity_numeric_kind_t= 값이다. */
uint32_t flags; /**< V1 quantity에는 정의된 bit가 없어 반드시 0이다. */
math_engine_quantity_numeric_storage_t numeric; /**< =numeric_kind=가 선택한 pointer-free 값 storage다. */
math_engine_unit_t unit; /**< Numeric 값이 표현된 차원·scale·offset의 값 소유 unit descriptor다. */
} math_engine_quantity_t;
math_engine_quantity_t.struct_size
Exact ABI byte 크기
sizeof(math_engine_quantity_t)다.uint32_t struct_size;
math_engine_quantity_t.struct_version
MATH_ENGINE_QUANTITY_VERSION_1이어야 한다.uint32_t struct_version;
math_engine_quantity_t.numeric_kind
numeric에서 활성인math_engine_quantity_numeric_kind_t값이다.uint32_t numeric_kind;
math_engine_quantity_t.flags
V1 quantity에는 정의된 bit가 없어 반드시 0이다.
uint32_t flags;
math_engine_quantity_t.numeric
numeric_kind가 선택한 pointer-free 값 storage다.math_engine_quantity_numeric_storage_t numeric;
math_engine_quantity_t.unit
Numeric 값이 표현된 차원·scale·offset의 값 소유 unit descriptor다.
math_engine_unit_t unit;
math_engine_quantity_request_t
Arithmetic, conversion and parse options. precision_context points to a caller-owned math_engine_precision_context_t in full builds. precision_output must name an already acquired slot when the result kind is precision decimal.
typedef struct math_engine_quantity_request {
uint32_t struct_size; /**< Caller가 exact request byte 크기로 설정한다. */
uint32_t struct_version; /**< =MATH_ENGINE_QUANTITY_REQUEST_VERSION_1=이어야 한다. */
uint32_t result_numeric_kind; /**< 결과에 요구하는 유효 non-INVALID numeric kind다. */
int32_t fixed_scale; /**< FIXED_DECIMAL 결과에서 사용할 포함 범위 0..18; 다른 kind에서는 무시된다. */
uint32_t rounding; /**< Fixed 결과의 =math_engine_decimal_rounding_t= 값이며 다른 kind에서는 무시된다. */
int32_t power; /**< POWER operation의 signed integer exponent이며 다른 operation에서는 무시된다. */
uint32_t flags; /**< V1 request에는 정의된 bit가 없어 반드시 0이다. */
uint32_t reserved32; /**< Caller는 0으로 두며 V1 validator가 nonzero를 거부한다. */
void* precision_context; /**< Precision source/result에서 필수인 borrowed caller-owned context; nullable otherwise, 호출 동안 유효하고 보관되지 않으며 caller가 직렬화한다. */
math_engine_quantity_precision_ref_t precision_output; /**< Precision 결과를 commit할 이미 획득한 writable slot; 다른 result kind에서는 무시된다. */
uint64_t reserved[2]; /**< Caller가 0으로 두어야 하고 V1 validator가 검사하는 ABI 확장 word다. */
} math_engine_quantity_request_t;
math_engine_quantity_request_t.struct_size
Caller가 exact request byte 크기로 설정한다.
uint32_t struct_size;
math_engine_quantity_request_t.struct_version
MATH_ENGINE_QUANTITY_REQUEST_VERSION_1이어야 한다.uint32_t struct_version;
math_engine_quantity_request_t.result_numeric_kind
결과에 요구하는 유효 non-INVALID numeric kind다.
uint32_t result_numeric_kind;
math_engine_quantity_request_t.fixed_scale
FIXED_DECIMAL 결과에서 사용할 포함 범위 0..18; 다른 kind에서는 무시된다.
int32_t fixed_scale;
math_engine_quantity_request_t.rounding
Fixed 결과의
math_engine_decimal_rounding_t값이며 다른 kind에서는 무시된다.uint32_t rounding;
math_engine_quantity_request_t.power
POWER operation의 signed integer exponent이며 다른 operation에서는 무시된다.
int32_t power;
math_engine_quantity_request_t.flags
V1 request에는 정의된 bit가 없어 반드시 0이다.
uint32_t flags;
math_engine_quantity_request_t.reserved32
Caller는 0으로 두며 V1 validator가 nonzero를 거부한다.
uint32_t reserved32;
math_engine_quantity_request_t.precision_context
Precision source/result에서 필수인 borrowed caller-owned context; nullable otherwise, 호출 동안 유효하고 보관되지 않으며 caller가 직렬화한다.
void* precision_context;
math_engine_quantity_request_t.precision_output
Precision 결과를 commit할 이미 획득한 writable slot; 다른 result kind에서는 무시된다.
math_engine_quantity_precision_ref_t precision_output;
math_engine_quantity_request_t.reserved
Caller가 0으로 두어야 하고 V1 validator가 검사하는 ABI 확장 word다.
uint64_t reserved[2];
math_engine_quantity_result_t
Auditable operation result. Only committed on success.
typedef struct math_engine_quantity_result {
uint32_t struct_size; /**< Caller가 exact result byte 크기로 미리 설정한다. */
uint32_t struct_version; /**< =MATH_ENGINE_QUANTITY_RESULT_VERSION_1=이어야 한다. */
uint32_t operation; /**< 성공한 =math_engine_quantity_operation_t= provenance 값이다. */
uint32_t flags; /**< EXACT/INEXACT와 선택적 rounding/unit/backend provenance bit의 OR다. */
uint32_t source_numeric_kind; /**< Parse에서는 requested kind, 그 밖에는 첫 source quantity의 numeric kind다. */
uint32_t result_numeric_kind; /**< =quantity.numeric_kind=와 같은 실제 결과 backend kind다. */
uint64_t operation_fingerprint; /**< Operation, source/result kind, flags와 결과 payload의 결정적 64-bit hash다. */
math_engine_quantity_t quantity; /**< 성공한 값과 명시적 결과 unit을 소유하는 versioned quantity다. */
uint64_t reserved[2]; /**< Library가 0으로 기록하고 caller가 무시하는 ABI 확장 word다. */
} math_engine_quantity_result_t;
math_engine_quantity_result_t.struct_size
Caller가 exact result byte 크기로 미리 설정한다.
uint32_t struct_size;
math_engine_quantity_result_t.struct_version
MATH_ENGINE_QUANTITY_RESULT_VERSION_1이어야 한다.uint32_t struct_version;
math_engine_quantity_result_t.operation
성공한
math_engine_quantity_operation_tprovenance 값이다.uint32_t operation;
math_engine_quantity_result_t.flags
EXACT/INEXACT와 선택적 rounding/unit/backend provenance bit의 OR다.
uint32_t flags;
math_engine_quantity_result_t.source_numeric_kind
Parse에서는 requested kind, 그 밖에는 첫 source quantity의 numeric kind다.
uint32_t source_numeric_kind;
math_engine_quantity_result_t.result_numeric_kind
quantity.numeric_kind와 같은 실제 결과 backend kind다.uint32_t result_numeric_kind;
math_engine_quantity_result_t.operation_fingerprint
Operation, source/result kind, flags와 결과 payload의 결정적 64-bit hash다.
uint64_t operation_fingerprint;
math_engine_quantity_result_t.quantity
성공한 값과 명시적 결과 unit을 소유하는 versioned quantity다.
math_engine_quantity_t quantity;
math_engine_quantity_result_t.reserved
Library가 0으로 기록하고 caller가 무시하는 ABI 확장 word다.
uint64_t reserved[2];
math_engine_constant_record_t
Process-lifetime immutable engineering/physical constant record.
typedef struct math_engine_constant_record {
uint32_t struct_size; /**< Engine record의 exact byte 크기 =sizeof(math_engine_constant_record_t)=다. */
uint32_t struct_version; /**< =MATH_ENGINE_CONSTANT_RECORD_VERSION_1=이다. */
uint64_t stable_id; /**< Name-domain에서 결정적으로 생성한 process/version 간 nonzero catalog ID다. */
uint32_t flags; /**< =MATH_ENGINE_CONSTANT_FLAG_*= 중 알려진 provenance/lifecycle bit의 OR다. */
uint32_t reserved32; /**< Engine이 0으로 제공하고 consumer가 무시하는 ABI 확장 slot이다. */
const char* canonical_name; /**< Non-NULL engine-owned NUL-terminated canonical UTF-8/ASCII 이름; process lifetime 동안 유효하다. */
const char* symbol; /**< Non-NULL engine-owned NUL-terminated 표준 symbol; process lifetime 동안 유효하다. */
const char* ascii_alias; /**< Non-NULL engine-owned NUL-terminated ASCII 검색 alias; process lifetime 동안 유효하다. */
const char* value_decimal; /**< Non-NULL engine-owned canonical decimal 값 text; process lifetime 동안 유효하다. */
const char* standard_uncertainty_decimal; /**< Non-NULL engine-owned standard-uncertainty decimal text; exact record는 ="0"=이다. */
const char* unit_expression; /**< Non-NULL engine-owned parseable canonical unit expression; process lifetime 동안 유효하다. */
const char* edition; /**< Non-NULL engine-owned source edition/revision text; process lifetime 동안 유효하다. */
const char* provenance; /**< Non-NULL engine-owned provenance/authority text; process lifetime 동안 유효하다. */
const char* legacy_disposition; /**< Non-NULL engine-owned migration/disposition text이며 없으면 빈 문자열이다. */
uint64_t replacement_stable_id; /**< DEPRECATED record의 대체 catalog ID이며 대체가 없으면 0이다. */
math_engine_quantity_t value; /**< =value_decimal=을 binary64로 materialize한 값과 명시적 unit이다. */
double standard_uncertainty; /**< =value=와 같은 unit의 finite nonnegative 1-sigma uncertainty; exact이면 0이다. */
} math_engine_constant_record_t;
math_engine_constant_record_t.struct_size
Engine record의 exact byte 크기
sizeof(math_engine_constant_record_t)다.uint32_t struct_size;
math_engine_constant_record_t.struct_version
MATH_ENGINE_CONSTANT_RECORD_VERSION_1이다.uint32_t struct_version;
math_engine_constant_record_t.stable_id
Name-domain에서 결정적으로 생성한 process/version 간 nonzero catalog ID다.
uint64_t stable_id;
math_engine_constant_record_t.flags
MATH_ENGINE_CONSTANT_FLAG_*중 알려진 provenance/lifecycle bit의 OR다.uint32_t flags;
math_engine_constant_record_t.reserved32
Engine이 0으로 제공하고 consumer가 무시하는 ABI 확장 slot이다.
uint32_t reserved32;
math_engine_constant_record_t.canonical_name
Non-NULL engine-owned NUL-terminated canonical UTF-8/ASCII 이름; process lifetime 동안 유효하다.
const char* canonical_name;
math_engine_constant_record_t.symbol
Non-NULL engine-owned NUL-terminated 표준 symbol; process lifetime 동안 유효하다.
const char* symbol;
math_engine_constant_record_t.ascii_alias
Non-NULL engine-owned NUL-terminated ASCII 검색 alias; process lifetime 동안 유효하다.
const char* ascii_alias;
math_engine_constant_record_t.value_decimal
Non-NULL engine-owned canonical decimal 값 text; process lifetime 동안 유효하다.
const char* value_decimal;
math_engine_constant_record_t.standard_uncertainty_decimal
Non-NULL engine-owned standard-uncertainty decimal text; exact record는 ="0"=이다.
const char* standard_uncertainty_decimal;
math_engine_constant_record_t.unit_expression
Non-NULL engine-owned parseable canonical unit expression; process lifetime 동안 유효하다.
const char* unit_expression;
math_engine_constant_record_t.edition
Non-NULL engine-owned source edition/revision text; process lifetime 동안 유효하다.
const char* edition;
math_engine_constant_record_t.provenance
Non-NULL engine-owned provenance/authority text; process lifetime 동안 유효하다.
const char* provenance;
math_engine_constant_record_t.legacy_disposition
Non-NULL engine-owned migration/disposition text이며 없으면 빈 문자열이다.
const char* legacy_disposition;
math_engine_constant_record_t.replacement_stable_id
DEPRECATED record의 대체 catalog ID이며 대체가 없으면 0이다.
uint64_t replacement_stable_id;
math_engine_constant_record_t.value
value_decimal을 binary64로 materialize한 값과 명시적 unit이다.math_engine_quantity_t value;
math_engine_constant_record_t.standard_uncertainty
value와 같은 unit의 finite nonnegative 1-sigma uncertainty; exact이면 0이다.double standard_uncertainty;
Macro와 constant
MATH_ENGINE_CONSTANT_FLAG_CONVENTIONAL
Bit 3 (0x08): 국제 협약으로 정한 conventional 값이다.
#define MATH_ENGINE_CONSTANT_FLAG_CONVENTIONAL (UINT32_C(1) << 3u)
MATH_ENGINE_CONSTANT_FLAG_DEPRECATED
Bit 5 (0x20): Catalog consumer가 대체 stable ID/disposition을 확인해야 하는 record다.
#define MATH_ENGINE_CONSTANT_FLAG_DEPRECATED (UINT32_C(1) << 5u)
MATH_ENGINE_CONSTANT_FLAG_DERIVED
Bit 2 (0x04): 다른 표준 상수나 식에서 유도된 값이다.
#define MATH_ENGINE_CONSTANT_FLAG_DERIVED (UINT32_C(1) << 2u)
MATH_ENGINE_CONSTANT_FLAG_EXACT
Bit 0 (0x01): 정의 또는 conventional 값으로 exact하며 uncertainty가 0이다.
#define MATH_ENGINE_CONSTANT_FLAG_EXACT (UINT32_C(1) << 0u)
MATH_ENGINE_CONSTANT_FLAG_KNOWN_MASK
V1에서 알려진 flag bit 0..5의 mask =0x0000003f=다.
#define MATH_ENGINE_CONSTANT_FLAG_KNOWN_MASK UINT32_C(0x0000003f)
MATH_ENGINE_CONSTANT_FLAG_MEASURED
Bit 1 (0x02): 측정 기반 값이며 EXACT와 배타적이고 positive uncertainty를 갖는다.
#define MATH_ENGINE_CONSTANT_FLAG_MEASURED (UINT32_C(1) << 1u)
MATH_ENGINE_CONSTANT_FLAG_SI_DEFINING
Bit 4 (0x10): 현행 SI 정의를 구성하는 exact defining constant다.
#define MATH_ENGINE_CONSTANT_FLAG_SI_DEFINING (UINT32_C(1) << 4u)
MATH_ENGINE_CONSTANT_RECORD_VERSION_1
math_engine_constant_record_t.struct_version 의 최초 unsigned ABI 값 1이다.
#define MATH_ENGINE_CONSTANT_RECORD_VERSION_1 UINT32_C(1)
MATH_ENGINE_QUANTITY_REQUEST_VERSION_1
math_engine_quantity_request_t.struct_version 의 최초 unsigned ABI 값 1이다.
#define MATH_ENGINE_QUANTITY_REQUEST_VERSION_1 UINT32_C(1)
MATH_ENGINE_QUANTITY_RESULT_FLAG_BACKEND_CONVERTED
Bit 4 (0x10): Source와 다른 numeric backend로 결과를 표현했다.
#define MATH_ENGINE_QUANTITY_RESULT_FLAG_BACKEND_CONVERTED (UINT32_C(1) << 4u)
MATH_ENGINE_QUANTITY_RESULT_FLAG_EXACT
Bit 0 (0x01): 결과가 선택 backend에서 exact하며 INEXACT와 함께 설정되지 않는다.
#define MATH_ENGINE_QUANTITY_RESULT_FLAG_EXACT (UINT32_C(1) << 0u)
MATH_ENGINE_QUANTITY_RESULT_FLAG_INEXACT
Bit 1 (0x02): 표현 또는 연산 과정에서 exact 값을 보존하지 못했다.
#define MATH_ENGINE_QUANTITY_RESULT_FLAG_INEXACT (UINT32_C(1) << 1u)
MATH_ENGINE_QUANTITY_RESULT_FLAG_ROUNDED
Bit 2 (0x04): 지정 rounding 정책에 따른 양자화가 실제로 발생했다.
#define MATH_ENGINE_QUANTITY_RESULT_FLAG_ROUNDED (UINT32_C(1) << 2u)
MATH_ENGINE_QUANTITY_RESULT_FLAG_UNIT_CONVERTED
Bit 3 (0x08): Source와 다른 호환 unit transform을 적용했다.
#define MATH_ENGINE_QUANTITY_RESULT_FLAG_UNIT_CONVERTED (UINT32_C(1) << 3u)
MATH_ENGINE_QUANTITY_RESULT_VERSION_1
math_engine_quantity_result_t.struct_version 의 최초 unsigned ABI 값 1이다.
#define MATH_ENGINE_QUANTITY_RESULT_VERSION_1 UINT32_C(1)
MATH_ENGINE_QUANTITY_TEXT_MAX_BYTES
Parse/format quantity와 unit-expression 입력의 포함 byte 상한 256이다.
#define MATH_ENGINE_QUANTITY_TEXT_MAX_BYTES UINT64_C(256)
MATH_ENGINE_QUANTITY_VERSION_1
math_engine_quantity_t.struct_version 의 최초 unsigned ABI 값 1이다.
#define MATH_ENGINE_QUANTITY_VERSION_1 UINT32_C(1)
Function
math_engine_quantity_init_binary32
유한 binary32 값과 명시적 단위로 quantity를 초기화한다.
- 매개변수
value: 단위에 표현된 유한 binary32 값. - 매개변수
unit: 복사할 검증된 단위. - 매개변수
out_quantity: 성공 시 초기화된 quantity를 받는 출력. 실패하면 보존된다. - 반환: 성공하면 OK, NULL·잘못된 단위면 검증 오류, 비유한 값이면 NON_FINITE.
- Math Engine ownership:
unit=borrowed out_quantity=caller - Math Engine nullable:
unit=false out_quantity=false - Math Engine thread_safety:
safe
MATH_ENGINE_API math_engine_status_t math_engine_quantity_init_binary32(
float value, const math_engine_unit_t* unit, math_engine_quantity_t* out_quantity);
math_engine_quantity_init_binary64
유한 binary64 값과 명시적 단위로 quantity를 초기화한다.
- 매개변수
value: 단위에 표현된 유한 binary64 값. - 매개변수
unit: 복사할 검증된 단위. - 매개변수
out_quantity: 성공 시 초기화된 quantity를 받는 출력. 실패하면 보존된다. - 반환: 성공하면 OK, NULL·잘못된 단위면 검증 오류, 비유한 값이면 NON_FINITE.
- Math Engine ownership:
unit=borrowed out_quantity=caller - Math Engine nullable:
unit=false out_quantity=false - Math Engine thread_safety:
safe
MATH_ENGINE_API math_engine_status_t math_engine_quantity_init_binary64(
double value, const math_engine_unit_t* unit, math_engine_quantity_t* out_quantity);
math_engine_quantity_init_fixed
coefficient * 10^-scale fixed decimal과 단위로 quantity를 초기화한다.
- 매개변수
coefficient: signed 64-bit decimal coefficient. - 매개변수
scale: 0..18 범위의 10진 소수 자릿수. - 매개변수
unit: 복사할 검증된 단위. - 매개변수
out_quantity: 성공 시 초기화된 quantity를 받는 출력. 실패하면 보존된다. - 반환: 성공하면 OK, scale 범위 밖이면 OUT_OF_RANGE, 그 밖의 입력 오류면 해당 status.
- Math Engine ownership:
unit=borrowed out_quantity=caller - Math Engine nullable:
unit=false out_quantity=false - Math Engine thread_safety:
safe
MATH_ENGINE_API math_engine_status_t math_engine_quantity_init_fixed(
int64_t coefficient, int32_t scale, const math_engine_unit_t* unit,
math_engine_quantity_t* out_quantity);
math_engine_quantity_init_precision
이미 획득한 precision-decimal slot 참조와 단위로 quantity를 초기화한다.
- 매개변수
value: 0이 아닌 context_id와 generation을 가진 caller-managed slot 참조. - 매개변수
unit: 복사할 검증된 단위. - 매개변수
out_quantity: 성공 시 초기화된 pointer-free quantity를 받는 출력. 실패하면 보존된다. - 반환: 성공하면 OK, 잘못된 참조·NULL·단위 오류면 해당 status.
- Math Engine ownership:
unit=borrowed out_quantity=caller - Math Engine nullable:
unit=false out_quantity=false - Math Engine thread_safety:
safe
@details 이 함수는 slot의 존재를 context에서 조회하지 않고 참조 형식만 검증한다.
MATH_ENGINE_API math_engine_status_t math_engine_quantity_init_precision(
math_engine_quantity_precision_ref_t value, const math_engine_unit_t* unit,
math_engine_quantity_t* out_quantity);
math_engine_quantity_validate
Quantity의 version, numeric storage와 단위를 구조적으로 검증한다.
- 매개변수
quantity: 검사할 읽기 전용 quantity. - 반환: 유효하면 OK, 크기·버전·numeric kind·유한성·단위 오류면 해당 status.
- Math Engine ownership:
quantity=borrowed - Math Engine nullable:
quantity=false - Math Engine thread_safety:
safe
MATH_ENGINE_API math_engine_status_t math_engine_quantity_validate(
const math_engine_quantity_t* quantity);
math_engine_quantity_convert_unit
같은 차원의 target 단위로 값을 변환하되 원래 numeric backend를 유지한다.
- 매개변수
quantity: 변환할 읽기 전용 quantity. - 매개변수
target_unit: 결과에 사용할 호환 단위. - 매개변수
request: fixed scale 또는 precision context를 포함한 변환 정책. - 매개변수
out_result: 미리 size/version을 설정한 결과 출력. 실패하면 보존된다. - 반환: 성공하면 OK, 차원·단위·backend·overflow·context 오류면 해당 status.
- Math Engine ownership:
quantity=borrowed target_unit=borrowed request=borrowed out_result=caller - Math Engine nullable:
quantity=false target_unit=false request=false out_result=false - Math Engine thread_safety:
conditional
@details Precision decimal이 관여하면 request->precision_context에 대한 외부 동기화가 필요하다.
MATH_ENGINE_API math_engine_status_t math_engine_quantity_convert_unit(
const math_engine_quantity_t* quantity, const math_engine_unit_t* target_unit,
const math_engine_quantity_request_t* request,
math_engine_quantity_result_t* out_result);
math_engine_quantity_convert_numeric
Quantity의 단위를 유지하면서 request가 지정한 numeric backend로 변환한다.
- 매개변수
quantity: 변환할 읽기 전용 quantity. - 매개변수
request: 결과 kind, fixed scale/rounding 또는 precision output slot 정책. - 매개변수
out_result: 미리 size/version을 설정한 결과 출력. 실패하면 보존된다. - 반환: 성공하면 OK, 지원하지 않는 profile·손실 변환·overflow·context 오류면 해당 status.
- Math Engine ownership:
quantity=borrowed request=borrowed out_result=caller - Math Engine nullable:
quantity=false request=false out_result=false - Math Engine thread_safety:
conditional
@details Precision source 또는 결과를 사용하면 request->precision_context를 호출자가 직렬화한다.
MATH_ENGINE_API math_engine_status_t math_engine_quantity_convert_numeric(
const math_engine_quantity_t* quantity,
const math_engine_quantity_request_t* request,
math_engine_quantity_result_t* out_result);
math_engine_quantity_evaluate
두 quantity의 산술 또는 lhs의 정수 거듭제곱을 명시한 backend로 평가한다.
- 매개변수
operation: ADD, SUBTRACT, MULTIPLY, DIVIDE 또는 POWER. - 매개변수
lhs: 첫 피연산자. - 매개변수
rhs: 둘째 피연산자. POWER에서만 NULL이어도 된다. - 매개변수
request: 결과 backend, fixed rounding과 POWER 지수를 담은 정책. - 매개변수
out_result: 단위·정확도 flag·fingerprint를 받는 출력. 실패하면 보존된다. - 반환: 성공하면 OK, 차원 불일치·affine 덧셈·0 나눗셈·overflow면 해당 status.
- Math Engine ownership:
lhs=borrowed rhs=borrowed request=borrowed out_result=caller - Math Engine nullable:
lhs=false rhs=true request=false out_result=false - Math Engine thread_safety:
conditional
@details Precision backend 경로는 request->precision_context와 output slot을 변경하므로 외부 동기화가 필요하다.
MATH_ENGINE_API math_engine_status_t math_engine_quantity_evaluate(
math_engine_quantity_operation_t operation,
const math_engine_quantity_t* lhs, const math_engine_quantity_t* rhs,
const math_engine_quantity_request_t* request,
math_engine_quantity_result_t* out_result);
math_engine_unit_parse_expression
factor, *, /, 괄호와 ^정수로 이루어진 제한된 ASCII 단위 표현식을 해석한다.
- 매개변수
text: NUL 종료에 의존하지 않는 입력 byte 배열. - 매개변수
text_size: 1..256 범위의 byte 수. - 매개변수
out_unit: 성공 시 정규화된 단위를 받는 출력. 실패하면 보존된다. - 반환: 성공하면 OK, 문법·catalog·길이·단위 오류면 해당 status.
- Math Engine ownership:
text=borrowed out_unit=caller - Math Engine nullable:
text=false out_unit=false - Math Engine thread_safety:
safe
MATH_ENGINE_API math_engine_status_t math_engine_unit_parse_expression(
const char* text, uint64_t text_size, math_engine_unit_t* out_unit);
math_engine_unit_format_expression
단위를 locale 독립 canonical ASCII 표현식과 NUL로 출력한다.
- 매개변수
unit: 포맷할 검증된 단위. - 매개변수
buffer: 결과를 받을 호출자 buffer. capacity가 0이면 NULL이어도 된다. - 매개변수
capacity: NUL을 포함한 buffer byte 용량. - 매개변수
out_size: NUL을 제외한 필요/출력 byte 수. 작은 buffer에서도 설정된다. - 반환: 성공하면 OK, 작은 buffer면 INSUFFICIENT_BUFFER, 단위·포인터 오류면 해당 status.
- Math Engine ownership:
unit=borrowed buffer=caller out_size=caller - Math Engine nullable:
unit=false buffer=capacity_zero_only out_size=false - Math Engine thread_safety:
safe
@details buffer와 out_size는 겹치면 안 된다. 작은 buffer에서는 buffer를 변경하지 않는다.
MATH_ENGINE_API math_engine_status_t math_engine_unit_format_expression(
const math_engine_unit_t* unit, char* buffer, uint64_t capacity,
uint64_t* out_size);
math_engine_quantity_parse
~<number><ASCII whitespace><unit expression>~을 request backend의 quantity로 해석한다.
- 매개변수
text: NUL 종료에 의존하지 않는 1..256 byte ASCII 입력. - 매개변수
text_size: 입력 byte 수. - 매개변수
request: 결과 backend, fixed scale/rounding 또는 precision output slot 정책. - 매개변수
out_result: 파싱된 quantity와 정확도 flag를 받는 출력. 실패하면 보존된다. - 반환: 성공하면 OK, 문법·단위·범위·backend·context 오류면 해당 status.
- Math Engine ownership:
text=borrowed request=borrowed out_result=caller - Math Engine nullable:
text=false request=false out_result=false - Math Engine thread_safety:
conditional
@details Precision 결과를 쓰면 request->precision_context에 대한 외부 동기화가 필요하다.
MATH_ENGINE_API math_engine_status_t math_engine_quantity_parse(
const char* text, uint64_t text_size,
const math_engine_quantity_request_t* request,
math_engine_quantity_result_t* out_result);
math_engine_quantity_format
Quantity를 locale 독립 <number> <unit> ASCII와 NUL로 출력한다.
- 매개변수
quantity: 포맷할 검증된 quantity. - 매개변수
precision_context: precision quantity의 slot을 읽을 context. 다른 kind에서는 NULL 가능하다. - 매개변수
buffer: 결과를 받을 호출자 buffer. capacity가 0이면 NULL이어도 된다. - 매개변수
capacity: NUL을 포함한 buffer byte 용량. - 매개변수
out_size: NUL을 제외한 필요/출력 byte 수. 작은 buffer에서도 설정된다. - 반환: 성공하면 OK, 작은 buffer면 INSUFFICIENT_BUFFER, backend·context 오류면 해당 status.
- Math Engine ownership:
quantity=borrowed precision_context=borrowed buffer=caller out_size=caller - Math Engine nullable:
quantity=false precision_context=true buffer=capacity_zero_only out_size=false - Math Engine thread_safety:
conditional
@details Precision context 사용 시 외부 동기화가 필요하다. 작은 buffer에서는 buffer를 변경하지 않는다.
MATH_ENGINE_API math_engine_status_t math_engine_quantity_format(
const math_engine_quantity_t* quantity, const void* precision_context,
char* buffer, uint64_t capacity, uint64_t* out_size);
math_engine_constant_catalog_count
Process-lifetime 불변 공학·물리 상수 record 수를 반환한다.
- 반환: catalog의 전체 record 수.
- Math Engine thread_safety:
safe
MATH_ENGINE_API size_t math_engine_constant_catalog_count(void);
math_engine_constant_catalog_at
Index로 process-lifetime 불변 상수 record를 조회한다.
- 매개변수
index: 0부터 시작하는 catalog index. - 반환: 범위 안이면 engine 소유 record의 borrowed pointer, 아니면 NULL.
- Math Engine ownership:
return=static - Math Engine nullable:
return=true - Math Engine thread_safety:
safe
MATH_ENGINE_API const math_engine_constant_record_t* math_engine_constant_catalog_at(
size_t index);
math_engine_constant_catalog_find
Canonical name, symbol 또는 ASCII alias가 정확히 일치하는 상수를 찾는다.
- 매개변수
alias: 최대 127 byte의 NUL 종료 검색 문자열. - 매개변수
out_record: 성공 시 engine 소유 불변 record의 borrowed pointer를 받는 출력. 실패하면 보존된다. - 반환: 찾으면 OK, 없으면 OUT_OF_RANGE, 포인터·길이 오류면 INVALID_ARGUMENT.
- Math Engine ownership:
alias=borrowed out_record=caller - Math Engine nullable:
alias=false out_record=false - Math Engine thread_safety:
safe
MATH_ENGINE_API math_engine_status_t math_engine_constant_catalog_find(
const char* alias, const math_engine_constant_record_t** out_record);
math_engine_constant_catalog_find_id
0이 아닌 stable ID로 상수 record를 찾는다.
- 매개변수
stable_id: catalog가 발행한 안정 식별자. - 매개변수
out_record: 성공 시 engine 소유 불변 record의 borrowed pointer를 받는 출력. 실패하면 보존된다. - 반환: 찾으면 OK, 없으면 OUT_OF_RANGE, 0 ID 또는 NULL이면 INVALID_ARGUMENT.
- Math Engine ownership:
out_record=caller - Math Engine nullable:
out_record=false - Math Engine thread_safety:
safe
MATH_ENGINE_API math_engine_status_t math_engine_constant_catalog_find_id(
uint64_t stable_id, const math_engine_constant_record_t** out_record);
math_engine_constant_catalog_fingerprint
입력 provenance와 모든 record 계약에서 계산한 결정적 catalog fingerprint를 반환한다.
- 반환: 현재 내장 catalog의 64-bit fingerprint.
- Math Engine thread_safety:
safe
MATH_ENGINE_API uint64_t math_engine_constant_catalog_fingerprint(void);
math_engine_constant_catalog_input_sha256
Catalog 생성 입력의 lowercase SHA-256 문자열을 반환한다.
- 반환: Process lifetime 동안 유효한 engine 소유 NUL 종료 문자열.
- Math Engine ownership:
return=static - Math Engine nullable:
return=false - Math Engine thread_safety:
safe
MATH_ENGINE_API const char* math_engine_constant_catalog_input_sha256(void);