Table of Contents

Class MathUtils

Namespace
RichHudFramework
Assembly
RichHudClient.dll

Mathematical utilities, particularly work-arounds for missing BitConverter functionality in Space Engineers mod API.

public static class MathUtils
Inheritance
MathUtils

Methods

FloatToInt32Bits(float, bool)

Approximates a float to IEEE 754 single-precision (32-bit) bit encoding using truncation and clamping. Lossy conversion, not perfectly reversable with Int32ToFloat().

Created as an alternative to BitConverter single precision conversions not in Space Engineers mod API whitelist.

Does not handle denormalized values, perform rounding (truncates mantissa), or special case handling (Inf/NaN approximated).

public static uint FloatToInt32Bits(float value, bool invertSignBit = false)

Parameters

value float
invertSignBit bool

Set true to flip the sign bit s.t. sign bit is set for positives and zero for negatives. Useful for sorting keys.

Returns

uint

Approximate bitwise representation of the float value.

Int32ToFloat(uint, bool)

Reconstitutes a float from an approximate single-precision (32-bit) bit encoding. Lossy conversion, not perfectly reversable with FloatToInt32Bits().

Does not handle denormalized values, perform rounding (truncates mantissa) or special case handling (Inf/NaN approximated).

public static float Int32ToFloat(uint bits, bool isSignInverted = false)

Parameters

bits uint
isSignInverted bool

Indicates if the sign bit was inverted and needs to be flipped

Returns

float

Float value from approximate 32bit bitwise representation.