HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
UT_Digits Class Reference

Converts a double or float or half to the shortest accurate decimal possible. More...

#include <UT_Digits.h>

+ Inheritance diagram for UT_Digits:

Classes

struct  to_chars_result
 

Public Types

enum  Flags {
  GENERAL = 0, FIXED = 1, SCIENTIFIC = 2, BINARY = 4,
  OCTAL = 8, HEX = 12, BASE = 12, E_PLUS = 16,
  E_2 = 32
}
 

Public Member Functions

 UT_Digits ()
 Initialize to empty string. More...
 
void reset (fpreal64, Flags flags=GENERAL, int precision=-1)
 Change to a new 64-bit double. More...
 
void reset (fpreal32, Flags flags=GENERAL, int precision=-1)
 Change to a new 32-bit float. More...
 
void reset (fpreal16, Flags flags=GENERAL, int precision=-1)
 Change to a 16-bit IEEE "half". More...
 
void reset (int64, Flags flags=GENERAL, int precision=-1)
 Change to an integer. More...
 
void reset (int32, Flags flags=GENERAL, int precision=-1)
 Change to an integer. More...
 
void reset (uint64, Flags flags=GENERAL, int precision=-1)
 Change to an unsigned. More...
 
void reset (uint32, Flags flags=GENERAL, int precision=-1)
 Change to an unsigned. More...
 
 UT_Digits (fpreal64 i, Flags flags=GENERAL, int precision=-1)
 Constructors that do reset(i) More...
 
 UT_Digits (fpreal32 i, Flags flags=GENERAL, int precision=-1)
 
 UT_Digits (fpreal16 i, Flags flags=GENERAL, int precision=-1)
 
 UT_Digits (int64 i, Flags flags=GENERAL, int precision=-1)
 
 UT_Digits (int32 i, Flags flags=GENERAL, int precision=-1)
 
 UT_Digits (uint64 i, Flags flags=GENERAL, int precision=-1)
 
 UT_Digits (uint32 i, Flags flags=GENERAL, int precision=-1)
 
 UT_Digits (fpreal64 i, int precision)
 Constructors that take precision but no flags. More...
 
 UT_Digits (fpreal32 i, int precision)
 
 UT_Digits (fpreal16 i, int precision)
 
const char * c_str () const
 Return the formatted string, which is stored in an internal buffer. More...
 
const char * data () const
 Return the formatted string, which is stored in an internal buffer. More...
 
unsigned size () const
 Length of the string. More...
 
char operator[] (unsigned i) const
 get the bytes of the formatted text More...
 
 operator const char * () const
 Return the formatted string, which is stored in an internal buffer. More...
 
 operator fpreal64 () const
 
 operator bool () const
 Returns true if reset to a non-zero value. More...
 
bool operator!= (const char *) const
 String equality, useful for testing. More...
 
bool operator== (const char *v) const
 
void insert (unsigned i, const char *c, unsigned len)
 
void insert (unsigned i, char c, unsigned len=1)
 
void pad0 (Flags flags, int digits)
 add leading zeros so there are n digits More...
 
void grouping (Flags flags)
 insert commas every 3 leading digits (or _ every 4 for hex) More...
 
void prefix (Flags flags)
 add C prefix such as "0x" More...
 
void plus (bool space=false)
 add a '+' or ' ' to positive numbers More...
 
void uppercase ()
 
void append (char c)
 
char * write (char *start, char *end) const
 

Static Public Member Functions

static to_chars_result to_chars (char *start, char *end, fpreal64 v, Flags flags=GENERAL, int precision=-1)
 
static to_chars_result to_chars (char *start, char *end, fpreal32 v, Flags flags=GENERAL, int precision=-1)
 
static to_chars_result to_chars (char *start, char *end, fpreal16 v, Flags flags=GENERAL, int precision=-1)
 
static to_chars_result to_chars (char *start, char *end, int64 v)
 
static to_chars_result to_chars (char *start, char *end, int32 v)
 
static to_chars_result to_chars (char *start, char *end, uint64 v)
 
static to_chars_result to_chars (char *start, char *end, uint32 v)
 
static Flags toFlags (int base)
 
static to_chars_result to_chars (char *start, char *end, int64 v, int base)
 
static to_chars_result to_chars (char *start, char *end, int32 v, int base)
 
static to_chars_result to_chars (char *start, char *end, uint64 v, int base)
 
static to_chars_result to_chars (char *start, char *end, uint32 v, int base)
 

Detailed Description

Converts a double or float or half to the shortest accurate decimal possible.

Definition at line 22 of file UT_Digits.h.

Member Enumeration Documentation

Enumerator
GENERAL 

used FIXED or SCIENTIFIC depending on range, no trailing zeros

FIXED 

fixed-point

SCIENTIFIC 

exponential notation

BINARY 
OCTAL 
HEX 
BASE 

mask for BINARY, OCTAL, HEX

E_PLUS 

put a + sign on exponent (like printf)

E_2 

use at least 2 digits for exponent (like printf)

Definition at line 25 of file UT_Digits.h.

Constructor & Destructor Documentation

UT_Digits::UT_Digits ( )
inline

Initialize to empty string.

Definition at line 38 of file UT_Digits.h.

UT_Digits::UT_Digits ( fpreal64  i,
Flags  flags = GENERAL,
int  precision = -1 
)
inlineexplicit

Constructors that do reset(i)

Definition at line 55 of file UT_Digits.h.

UT_Digits::UT_Digits ( fpreal32  i,
Flags  flags = GENERAL,
int  precision = -1 
)
inlineexplicit

Definition at line 56 of file UT_Digits.h.

UT_Digits::UT_Digits ( fpreal16  i,
Flags  flags = GENERAL,
int  precision = -1 
)
inlineexplicit

Definition at line 57 of file UT_Digits.h.

UT_Digits::UT_Digits ( int64  i,
Flags  flags = GENERAL,
int  precision = -1 
)
inlineexplicit

Definition at line 58 of file UT_Digits.h.

UT_Digits::UT_Digits ( int32  i,
Flags  flags = GENERAL,
int  precision = -1 
)
inlineexplicit

Definition at line 59 of file UT_Digits.h.

UT_Digits::UT_Digits ( uint64  i,
Flags  flags = GENERAL,
int  precision = -1 
)
inlineexplicit

Definition at line 60 of file UT_Digits.h.

UT_Digits::UT_Digits ( uint32  i,
Flags  flags = GENERAL,
int  precision = -1 
)
inlineexplicit

Definition at line 61 of file UT_Digits.h.

UT_Digits::UT_Digits ( fpreal64  i,
int  precision 
)
inline

Constructors that take precision but no flags.

Definition at line 64 of file UT_Digits.h.

UT_Digits::UT_Digits ( fpreal32  i,
int  precision 
)
inline

Definition at line 65 of file UT_Digits.h.

UT_Digits::UT_Digits ( fpreal16  i,
int  precision 
)
inline

Definition at line 66 of file UT_Digits.h.

Member Function Documentation

void UT_Digits::append ( char  c)
inline

Definition at line 104 of file UT_Digits.h.

const char* UT_Digits::c_str ( void  ) const
inline

Return the formatted string, which is stored in an internal buffer.

Definition at line 69 of file UT_Digits.h.

const char* UT_Digits::data ( ) const
inline

Return the formatted string, which is stored in an internal buffer.

Definition at line 71 of file UT_Digits.h.

void UT_Digits::grouping ( Flags  flags)

insert commas every 3 leading digits (or _ every 4 for hex)

void UT_Digits::insert ( unsigned  i,
const char *  c,
unsigned  len 
)
void UT_Digits::insert ( unsigned  i,
char  c,
unsigned  len = 1 
)
UT_Digits::operator bool ( ) const
explicit

Returns true if reset to a non-zero value.

UT_Digits::operator const char * ( ) const
inline

Return the formatted string, which is stored in an internal buffer.

Definition at line 78 of file UT_Digits.h.

UT_Digits::operator fpreal64 ( ) const
explicit

Cast to a double that will format to the same digits. This is useful to convert a float or half to the "expected" double value.

bool UT_Digits::operator!= ( const char *  ) const

String equality, useful for testing.

bool UT_Digits::operator== ( const char *  v) const
inline

Definition at line 94 of file UT_Digits.h.

char UT_Digits::operator[] ( unsigned  i) const
inline

get the bytes of the formatted text

Definition at line 75 of file UT_Digits.h.

void UT_Digits::pad0 ( Flags  flags,
int  digits 
)

add leading zeros so there are n digits

void UT_Digits::plus ( bool  space = false)

add a '+' or ' ' to positive numbers

void UT_Digits::prefix ( Flags  flags)

add C prefix such as "0x"

void UT_Digits::reset ( fpreal64  ,
Flags  flags = GENERAL,
int  precision = -1 
)

Change to a new 64-bit double.

void UT_Digits::reset ( fpreal32  ,
Flags  flags = GENERAL,
int  precision = -1 
)

Change to a new 32-bit float.

void UT_Digits::reset ( fpreal16  ,
Flags  flags = GENERAL,
int  precision = -1 
)

Change to a 16-bit IEEE "half".

void UT_Digits::reset ( int64  ,
Flags  flags = GENERAL,
int  precision = -1 
)

Change to an integer.

void UT_Digits::reset ( int32  ,
Flags  flags = GENERAL,
int  precision = -1 
)

Change to an integer.

void UT_Digits::reset ( uint64  ,
Flags  flags = GENERAL,
int  precision = -1 
)

Change to an unsigned.

void UT_Digits::reset ( uint32  ,
Flags  flags = GENERAL,
int  precision = -1 
)

Change to an unsigned.

unsigned UT_Digits::size ( void  ) const
inline

Length of the string.

Definition at line 73 of file UT_Digits.h.

static to_chars_result UT_Digits::to_chars ( char *  start,
char *  end,
fpreal64  v,
Flags  flags = GENERAL,
int  precision = -1 
)
inlinestatic

Definition at line 114 of file UT_Digits.h.

static to_chars_result UT_Digits::to_chars ( char *  start,
char *  end,
fpreal32  v,
Flags  flags = GENERAL,
int  precision = -1 
)
inlinestatic

Definition at line 116 of file UT_Digits.h.

static to_chars_result UT_Digits::to_chars ( char *  start,
char *  end,
fpreal16  v,
Flags  flags = GENERAL,
int  precision = -1 
)
inlinestatic

Definition at line 118 of file UT_Digits.h.

static to_chars_result UT_Digits::to_chars ( char *  start,
char *  end,
int64  v 
)
inlinestatic

Definition at line 121 of file UT_Digits.h.

static to_chars_result UT_Digits::to_chars ( char *  start,
char *  end,
int32  v 
)
inlinestatic

Definition at line 123 of file UT_Digits.h.

static to_chars_result UT_Digits::to_chars ( char *  start,
char *  end,
uint64  v 
)
inlinestatic

Definition at line 125 of file UT_Digits.h.

static to_chars_result UT_Digits::to_chars ( char *  start,
char *  end,
uint32  v 
)
inlinestatic

Definition at line 127 of file UT_Digits.h.

static to_chars_result UT_Digits::to_chars ( char *  start,
char *  end,
int64  v,
int  base 
)
inlinestatic

Definition at line 131 of file UT_Digits.h.

static to_chars_result UT_Digits::to_chars ( char *  start,
char *  end,
int32  v,
int  base 
)
inlinestatic

Definition at line 133 of file UT_Digits.h.

static to_chars_result UT_Digits::to_chars ( char *  start,
char *  end,
uint64  v,
int  base 
)
inlinestatic

Definition at line 135 of file UT_Digits.h.

static to_chars_result UT_Digits::to_chars ( char *  start,
char *  end,
uint32  v,
int  base 
)
inlinestatic

Definition at line 137 of file UT_Digits.h.

static Flags UT_Digits::toFlags ( int  base)
inlinestatic

Definition at line 130 of file UT_Digits.h.

void UT_Digits::uppercase ( )
char* UT_Digits::write ( char *  start,
char *  end 
) const

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