llfix
Low-latency FIX engine
llfix::FixedPoint Class Reference

Represents an unsigned fixed-point numeric value with a configurable number of decimal points. Not general purpose, intended usage is for only exchange connectivity. More...

#include <fixed_point.h>

Public Member Functions

void set_decimal_points (uint32_t n)
 Set the number of decimal points for this value. More...
 
uint32_t get_decimal_points () const
 Get the number of decimal points for this value. More...
 
void set_raw_value (uint64_t raw_value)
 Set the raw integer value. More...
 
uint64_t get_raw_value () const
 Get the raw integer value. More...
 
void set_from_chars (const char *buffer, std::size_t length)
 Set value from a character buffer representing a decimal number. More...
 
std::size_t to_chars (char *buffer) const
 Convert the fixed-point value into characters in buffer. More...
 
std::string to_string () const
 Convert the fixed-point value to a std::string. More...
 
bool operator== (const FixedPoint &other) const
 Equality comparison.
 
bool operator!= (const FixedPoint &other) const
 Inequality comparison.
 
bool operator> (const FixedPoint &other) const
 Greater-than comparison.
 
bool operator>= (const FixedPoint &other) const
 Greater-than-or-equal comparison.
 
bool operator< (const FixedPoint &other) const
 Less-than comparison.
 
bool operator<= (const FixedPoint &other) const
 Less-than-or-equal comparison.
 

Detailed Description

Represents an unsigned fixed-point numeric value with a configurable number of decimal points. Not general purpose, intended usage is for only exchange connectivity.

  • Decimal points represent the scale factor. For example: in 10.32, decimal points = 2.
  • If decimal points is 4, a raw value of 10000 represents 1.0000.
  • Some common decimal point examples used by exchanges:
    • 4 (Nasdaq OMX)
    • 6 (Euronext)
    • 7 (Euronext)
    • 8 (Xetra & Eurex)
  • Raw value is stored as a 64-bit unsigned integer, matching typical exchange-native binary protocol fields (e.g. price).
  • Arithmetic operations not supported. You can use get_raw_value and set_raw_value to modify the underlying value
Warning
  1. You must not use a FixedPoint instance without setting decimal points.
  2. set_from_chars assumes a strictly valid unsigned decimal representation. Accepted format: digits with an optional single '.' delimiter (e.g. "123", "123.45"). The parser does not validate or skip whitespace, signs, separators, exponent notation, or multiple '.' characters. Any non-digit (other than a single '.') or multiple '.' occurrences yield undefined/implementation-specific results.

Usage

Example 1

FixedPoint fp;
fp.set_decimal_points(4);
fp.set_from_chars("1000.0023");
std::cout << fp.to_string(); // 1000.0023
std::cout << fp.get_raw_value(); // 10000023

Example 2

FixedPoint fp;
fp.set_decimal_points(4);
fp.set_raw_value(10001234);
std::cout << fp.to_string(); // 1000.1234
std::cout << fp.get_raw_value(); // 10001234

Member Function Documentation

◆ get_decimal_points()

uint32_t llfix::FixedPoint::get_decimal_points ( ) const
inline

Get the number of decimal points for this value.

Returns
Number of decimal points

◆ get_raw_value()

uint64_t llfix::FixedPoint::get_raw_value ( ) const
inline

Get the raw integer value.

Returns
Raw fixed-point value

◆ set_decimal_points()

void llfix::FixedPoint::set_decimal_points ( uint32_t  n)
inline

Set the number of decimal points for this value.

Parameters
nNumber of decimal points (max allowed value is 9)

◆ set_from_chars()

void llfix::FixedPoint::set_from_chars ( const char *  buffer,
std::size_t  length 
)
inline

Set value from a character buffer representing a decimal number.

Example: if decimal points = 4, input "10.2345" -> raw value = 102345

Parameters
bufferCharacter buffer containing the numeric value
lengthLength of the buffer

◆ set_raw_value()

void llfix::FixedPoint::set_raw_value ( uint64_t  raw_value)
inline

Set the raw integer value.

Parameters
raw_valueThe raw value corresponding to the fixed-point representation

◆ to_chars()

std::size_t llfix::FixedPoint::to_chars ( char *  buffer) const
inline

Convert the fixed-point value into characters in buffer.

Example: raw value 102345 with decimal points 4 -> buffer "10.2345"

Parameters
bufferTarget buffer to write characters
Returns
Number of characters written
Note
The output is NOT null-terminated; callers must append '\0' if a C-string is required.

◆ to_string()

std::string llfix::FixedPoint::to_string ( ) const
inline

Convert the fixed-point value to a std::string.

Returns
String representation including decimal point

The documentation for this class was generated from the following file: