yumapro  22.10T-4
YumaPro SDK
Loading...
Searching...
No Matches
YANG Number (ncx_num_t)

Make sure to include "ncxtypes.h" and "ncx_num.h" to use the ncx_num APIs. More...

Collaboration diagram for YANG Number (ncx_num_t):

Functions

void ncx_init_num (ncx_num_t *num)
 Init a ncx_num_t struct. More...
 
void ncx_clean_num (ncx_btype_t btyp, ncx_num_t *num)
 Scrub the memory in a ncx_num_t by freeing all the sub-fields. More...
 
int32 ncx_compare_nums (const ncx_num_t *num1, const ncx_num_t *num2, ncx_btype_t btyp)
 Compare 2 ncx_num_t union contents. More...
 
void ncx_set_num_min (ncx_num_t *num, ncx_btype_t btyp)
 Set a number to the minimum value for its type. More...
 
void ncx_set_num_max (ncx_num_t *num, ncx_btype_t btyp)
 Set a number to the maximum value for its type. More...
 
void ncx_set_num_one (ncx_num_t *num, ncx_btype_t btyp)
 Set a number to one. More...
 
void ncx_set_num_zero (ncx_num_t *num, ncx_btype_t btyp)
 Set a number to zero. More...
 
void ncx_set_num_nan (ncx_num_t *num, ncx_btype_t btyp)
 Set a FP number to the Not a Number value. More...
 
boolean ncx_num_is_nan (ncx_num_t *num, ncx_btype_t btyp)
 Check if a FP number is set to the Not a Number value. More...
 
boolean ncx_num_zero (const ncx_num_t *num, ncx_btype_t btyp)
 Compare a ncx_num_t to zero. More...
 
status_t ncx_convert_num (const xmlChar *numstr, ncx_numfmt_t numfmt, ncx_btype_t btyp, ncx_num_t *val)
 Convert a number string to a numeric type. More...
 
status_t ncx_convert_dec64 (const xmlChar *numstr, ncx_numfmt_t numfmt, uint8 digits, ncx_num_t *val)
 Convert a number string to a decimal64 number. More...
 
status_t ncx_convert_cbor_dec64 (int64 mantissa, int64 basenum, uint8 digits, ncx_num_t *val)
 Convert a CBOR decimal bignum to a decimal64 number. More...
 
status_t ncx_decode_num (const xmlChar *numstr, ncx_btype_t btyp, ncx_num_t *retnum)
 Handle some sort of number string. More...
 
status_t ncx_decode_num_ex (const xmlChar *numstr, ncx_btype_t btyp, ncx_num_t *retnum, typ_def_t *typdef)
 Handle some sort of number string EXTENDED. More...
 
status_t ncx_decode_dec64 (const xmlChar *numstr, uint8 digits, ncx_num_t *retnum)
 Handle some sort of decimal64 number string (NCX_BT_DECIMAL64) More...
 
status_t ncx_copy_num (const ncx_num_t *num1, ncx_num_t *num2, ncx_btype_t btyp)
 Copy the contents of num1 to num2. More...
 
status_t ncx_cast_num (const ncx_num_t *num1, ncx_btype_t btyp1, ncx_num_t *num2, ncx_btype_t btyp2)
 Cast a number as another number type. More...
 
status_t ncx_num_floor (const ncx_num_t *num1, ncx_num_t *num2, ncx_btype_t btyp)
 Get the floor value of a number. More...
 
status_t ncx_num_ceiling (const ncx_num_t *num1, ncx_num_t *num2, ncx_btype_t btyp)
 Get the ceiling value of a number. More...
 
status_t ncx_round_num (const ncx_num_t *num1, ncx_num_t *num2, ncx_btype_t btyp)
 Get the rounded value of a number. More...
 
boolean ncx_num_is_integral (const ncx_num_t *num, ncx_btype_t btyp)
 Check if the number is integral or if it has a fractional part. More...
 
int64 ncx_cvt_to_int64 (const ncx_num_t *num, ncx_btype_t btyp)
 Convert a number to an integer64; Use rounding for float64. More...
 
ncx_numfmt_t ncx_get_numfmt (const xmlChar *numstr)
 Get the number format of the specified string. More...
 
void ncx_printf_num (const ncx_num_t *num, ncx_btype_t btyp, log_debug_t level)
 Printf a ncx_num_t contents using logging functions. More...
 
void ncx_printf_num_ex (const ncx_num_t *num, ncx_btype_t btyp, log_debug_t level, FILE *overrideOut)
 Printf a ncx_num_t contents (write to a file) More...
 
void ncx_alt_printf_num (const ncx_num_t *num, ncx_btype_t btyp)
 Printf a ncx_num_t contents to the alternate log file. More...
 
void ncx_audit_printf_num (const ncx_num_t *num, ncx_btype_t btyp)
 Printf a ncx_num_t contents to the audit log file. More...
 
status_t ncx_sprintf_num (xmlChar *buff, const ncx_num_t *num, ncx_btype_t btyp, uint32 *len)
 Sprintf a ncx_num_t contents. More...
 
boolean ncx_is_min (const ncx_num_t *num, ncx_btype_t btyp)
 Return TRUE if the specified number is the min value for its type. More...
 
boolean ncx_is_max (const ncx_num_t *num, ncx_btype_t btyp)
 Return TRUE if the specified number is the max value for its type. More...
 
status_t ncx_convert_tkcnum (tk_chain_t *tkc, ncx_btype_t btyp, ncx_num_t *val)
 Convert the current token in a token chain to a ncx_num_t struct. More...
 
status_t ncx_convert_tkc_dec64 (tk_chain_t *tkc, uint8 digits, ncx_num_t *val)
 Convert the current token in a token chain to a ncx_num_t struct, expecting NCX_BT_DECIMAL64. More...
 
int64 ncx_get_dec64_base (const ncx_num_t *num)
 Get the base part of a decimal64 number. More...
 
int64 ncx_get_dec64_fraction (const ncx_num_t *num)
 Get the fraction part of a decimal64 number. More...
 
status_t ncx_set_num_from_uint64 (ncx_num_t *retval, uint64 val, ncx_btype_t btyp, boolean is_neg)
 Set the number from a uint64 plus sign flag. More...
 

Detailed Description

Make sure to include "ncxtypes.h" and "ncx_num.h" to use the ncx_num APIs.

Function Documentation

◆ ncx_alt_printf_num()

void ncx_alt_printf_num ( const ncx_num_t num,
ncx_btype_t  btyp 
)

Printf a ncx_num_t contents to the alternate log file.

Parameters
numnumber to printf
btypnumber base type
Here is the call graph for this function:
Here is the caller graph for this function:

◆ ncx_audit_printf_num()

void ncx_audit_printf_num ( const ncx_num_t num,
ncx_btype_t  btyp 
)

Printf a ncx_num_t contents to the audit log file.

Parameters
numnumber to printf
btypnumber base type
Here is the call graph for this function:
Here is the caller graph for this function:

◆ ncx_cast_num()

status_t ncx_cast_num ( const ncx_num_t num1,
ncx_btype_t  btyp1,
ncx_num_t num2,
ncx_btype_t  btyp2 
)

Cast a number as another number type.

  Supports all NCX numeric types:
     NCX_BT_INT*
     NCX_BT_UINT*
     NCX_BT_FLOAT64
Parameters
num1source number
btyp1expected data type of num1
num2target number
[out]btyp2desired data type of num2
  • *num2 set to cast value of num1
Returns
status
Here is the caller graph for this function:

◆ ncx_clean_num()

void ncx_clean_num ( ncx_btype_t  btyp,
ncx_num_t num 
)

Scrub the memory in a ncx_num_t by freeing all the sub-fields.

DOES NOT free the entire struct itself The struct must be removed from any queue it is in before this function is called.

Parameters
btypbase type of number
numncx_num_t data structure to clean
Here is the caller graph for this function:

◆ ncx_compare_nums()

int32 ncx_compare_nums ( const ncx_num_t num1,
const ncx_num_t num2,
ncx_btype_t  btyp 
)

Compare 2 ncx_num_t union contents.

Parameters
num1first number to compare
num2second number to compare
btypexpected data type (NCX_BT_INT, UINT, REAL)
Returns
compare value
      -1 if num1 is < num2
       0 if num1 == num2
       1 if num1 is > num2
Here is the call graph for this function:
Here is the caller graph for this function:

◆ ncx_convert_cbor_dec64()

status_t ncx_convert_cbor_dec64 ( int64  mantissa,
int64  basenum,
uint8  digits,
ncx_num_t val 
)

Convert a CBOR decimal bignum to a decimal64 number.

Special handling for decimal64 data type Convert a CBOR decimal fraction to a decimal64 number Received: Tag(4) [int64, int64] representing mantissa and base number

The CBOR representation must be converted to the internal dec64 representation. The saved shifted numer must have the same number of digits as the typedef

Checks for data type overflow, based on RFC 7950, sec. 9.3

Parameters
mantissamantissa from CBOR array first number
basenumbase number from CBOR array second number
digitsnumber of fixed-point digits expected
[out]valpointer to ncx_num_t to hold result
  • *val converted number value
Returns
status
Here is the call graph for this function:

◆ ncx_convert_dec64()

status_t ncx_convert_dec64 ( const xmlChar *  numstr,
ncx_numfmt_t  numfmt,
uint8  digits,
ncx_num_t val 
)

Convert a number string to a decimal64 number.

Special handling for decimal64 data type

Parameters
numstrnumber string
numfmtnumber format used
digitsnumber of fixed-point digits expected
[out]valpointer to ncx_num_t to hold result
  • *val converted number value
Returns
status
Here is the call graph for this function:
Here is the caller graph for this function:

◆ ncx_convert_num()

status_t ncx_convert_num ( const xmlChar *  numstr,
ncx_numfmt_t  numfmt,
ncx_btype_t  btyp,
ncx_num_t val 
)

Convert a number string to a numeric type.

Used by the XML and CLI parsers to convert numbers

Parameters
numstrnumber string to convert
numfmtNCX_NF_OCTAL, NCX_NF_DEC, NCX_NF_HEX, or NCX_NF_REAL
btypdesired number type (e.g., NCX_BT_INT32, NCX_BT_UINT32, NCX_BT_FLOAT64)
[out]valpointer to ncx_num_t to hold result
  • *val converted number value
Returns
status
Here is the call graph for this function:
Here is the caller graph for this function:

◆ ncx_convert_tkc_dec64()

status_t ncx_convert_tkc_dec64 ( tk_chain_t tkc,
uint8  digits,
ncx_num_t val 
)

Convert the current token in a token chain to a ncx_num_t struct, expecting NCX_BT_DECIMAL64.

Parameters
tkctoken chain; current token will be converted tkc->typ == TK_TT_DNUM, TK_TT_HNUM, TK_TT_RNUM
digitsnumber of expected decimal digits
[out]valaddress of return value
  • *val converted number value, if NO_ERR
Returns
status
Here is the call graph for this function:

◆ ncx_convert_tkcnum()

status_t ncx_convert_tkcnum ( tk_chain_t tkc,
ncx_btype_t  btyp,
ncx_num_t val 
)

Convert the current token in a token chain to a ncx_num_t struct.

Parameters
tkctoken chain; current token will be converted tkc->typ == TK_TT_DNUM, TK_TT_HNUM, TK_TT_RNUM
btypdesired number type (e.g., NCX_BT_INT32, NCX_BT_UINT64, NCX_BT_FLOAT64)
[out]valaddress of return value
  • *val converted number value (0..2G-1), if NO_ERR
Returns
status
Here is the call graph for this function:
Here is the caller graph for this function:

◆ ncx_copy_num()

status_t ncx_copy_num ( const ncx_num_t num1,
ncx_num_t num2,
ncx_btype_t  btyp 
)

Copy the contents of num1 to num2.

  Supports all NCX numeric types:
     NCX_BT_INT*
     NCX_BT_UINT*
     NCX_BT_DECIMAL64
     NCX_BT_FLOAT64
Parameters
num1source number
num2destination number
btypexpected data type (NCX_BT_INT, UINT, REAL)
Returns
status
Here is the caller graph for this function:

◆ ncx_cvt_to_int64()

int64 ncx_cvt_to_int64 ( const ncx_num_t num,
ncx_btype_t  btyp 
)

Convert a number to an integer64; Use rounding for float64.

Parameters
numnumber to convert
btypdata type of num
Returns
int64 representation

◆ ncx_decode_dec64()

status_t ncx_decode_dec64 ( const xmlChar *  numstr,
uint8  digits,
ncx_num_t retnum 
)

Handle some sort of decimal64 number string (NCX_BT_DECIMAL64)

Parameters
numstrnumber string
digitsnumber of expected digits for this decimal64
[out]retnumpointer to initialized ncx_num_t to hold result
  • *retnum converted number
Returns
status of the operation
Here is the call graph for this function:
Here is the caller graph for this function:

◆ ncx_decode_num()

status_t ncx_decode_num ( const xmlChar *  numstr,
ncx_btype_t  btyp,
ncx_num_t retnum 
)

Handle some sort of number string.

Parameters
numstrnumber string
btypdesired number type
[out]retnumpointer to initialized ncx_num_t to hold result
  • *retnum converted number
Returns
status of the operation
Here is the call graph for this function:
Here is the caller graph for this function:

◆ ncx_decode_num_ex()

status_t ncx_decode_num_ex ( const xmlChar *  numstr,
ncx_btype_t  btyp,
ncx_num_t retnum,
typ_def_t typdef 
)

Handle some sort of number string EXTENDED.

Parameters
numstrnumber string
btypdesired number type
retnumpointer to initialized ncx_num_t to hold result
[out]typdefnumber typedef
  • *retnum converted number
Returns
status of the operation
Here is the call graph for this function:
Here is the caller graph for this function:

◆ ncx_get_dec64_base()

int64 ncx_get_dec64_base ( const ncx_num_t num)

Get the base part of a decimal64 number.

Parameters
numnumber to check (expected to be NCX_BT_DECIMAL64)
Returns
base part of the number
Here is the caller graph for this function:

◆ ncx_get_dec64_fraction()

int64 ncx_get_dec64_fraction ( const ncx_num_t num)

Get the fraction part of a decimal64 number.

Parameters
numnumber to check (expected to be NCX_BT_DECIMAL64)
Returns
fraction part of the number
Here is the caller graph for this function:

◆ ncx_get_numfmt()

ncx_numfmt_t ncx_get_numfmt ( const xmlChar *  numstr)

Get the number format of the specified string.

Does not check for valid format Just figures out which type it must be if it were valid

Parameters
numstrnumber string
Returns
NCX_NF_NONE, NCX_NF_DEC, NCX_NF_HEX, or NCX_NF_REAL
Here is the caller graph for this function:

◆ ncx_init_num()

void ncx_init_num ( ncx_num_t num)

Init a ncx_num_t struct.

Parameters
numnumber to initialize
Here is the caller graph for this function:

◆ ncx_is_max()

boolean ncx_is_max ( const ncx_num_t num,
ncx_btype_t  btyp 
)

Return TRUE if the specified number is the max value for its type.

Parameters
numnumber to check
btypdata type of num
Returns
TRUE if this is the maximum value; FALSE otherwise

◆ ncx_is_min()

boolean ncx_is_min ( const ncx_num_t num,
ncx_btype_t  btyp 
)

Return TRUE if the specified number is the min value for its type.

Parameters
numnumber to check
btypdata type of num
Returns
TRUE if this is the minimum value; FALSE otherwise

◆ ncx_num_ceiling()

status_t ncx_num_ceiling ( const ncx_num_t num1,
ncx_num_t num2,
ncx_btype_t  btyp 
)

Get the ceiling value of a number.

  Supports all NCX numeric types:
     NCX_BT_INT*
     NCX_BT_UINT*
     NCX_BT_DECIMAL64
     NCX_BT_FLOAT64
Parameters
num1source number
num2address of target number
[out]btypexpected data type of numbers
  • *num2 set to ceiling of num1
Returns
status

◆ ncx_num_floor()

status_t ncx_num_floor ( const ncx_num_t num1,
ncx_num_t num2,
ncx_btype_t  btyp 
)

Get the floor value of a number.

  Supports all NCX numeric types:
     NCX_BT_INT*
     NCX_BT_UINT*
     NCX_BT_DECIMAL64
     NCX_BT_FLOAT64
Parameters
num1source number
num2address of target number
[out]btypexpected data type of numbers
  • *num2 set to floor of num1
Returns
status

◆ ncx_num_is_integral()

boolean ncx_num_is_integral ( const ncx_num_t num,
ncx_btype_t  btyp 
)

Check if the number is integral or if it has a fractional part.

  Supports all NCX numeric types:
     NCX_BT_INT*
     NCX_BT_UINT*
     NCX_BT_DECIMAL64
     NCX_BT_FLOAT64
Parameters
numnumber to check
btypexpected data type
Returns
TRUE if integral, FALSE if not

◆ ncx_num_is_nan()

boolean ncx_num_is_nan ( ncx_num_t num,
ncx_btype_t  btyp 
)

Check if a FP number is set to the Not a Number value.

Parameters
numnumber to set
btypexpected data type
Returns
TRUE if number is not-a-number (NaN); FALSE otherwise

◆ ncx_num_zero()

boolean ncx_num_zero ( const ncx_num_t num,
ncx_btype_t  btyp 
)

Compare a ncx_num_t to zero.

Parameters
numnumber to compare to zero
btypexpected data type (e.g., NCX_BT_INT32, NCX_BT_UINT64)
Returns
TRUE if value is equal to zero; FALSE if value is not equal to zero
Here is the caller graph for this function:

◆ ncx_printf_num()

void ncx_printf_num ( const ncx_num_t num,
ncx_btype_t  btyp,
log_debug_t  level 
)

Printf a ncx_num_t contents using logging functions.

Parameters
numnumber to printf
btypnumber base type
leveldebug level for output
Here is the call graph for this function:
Here is the caller graph for this function:

◆ ncx_printf_num_ex()

void ncx_printf_num_ex ( const ncx_num_t num,
ncx_btype_t  btyp,
log_debug_t  level,
FILE *  overrideOut 
)

Printf a ncx_num_t contents (write to a file)

Parameters
numnumber to printf
btypnumber base type
leveldebug level for output
overrideOutoutput file, or NULL for normal usage
Here is the call graph for this function:
Here is the caller graph for this function:

◆ ncx_round_num()

status_t ncx_round_num ( const ncx_num_t num1,
ncx_num_t num2,
ncx_btype_t  btyp 
)

Get the rounded value of a number.

  Supports all NCX numeric types:
     NCX_BT_INT*
     NCX_BT_UINT*
     NCX_BT_DECIMAL64
     NCX_BT_FLOAT64
Parameters
num1source number
num2address of target number
[out]btypexpected data type of numbers
  • *num2 set to round of num1
Returns
status

◆ ncx_set_num_from_uint64()

status_t ncx_set_num_from_uint64 ( ncx_num_t retval,
uint64  val,
ncx_btype_t  btyp,
boolean  is_neg 
)

Set the number from a uint64 plus sign flag.

Check the min and max values for the numeric base type

Parameters
[in,out]retvaladdress of number to fill in
  • *retval number is filled in
valvalue expressed as uint64
btypbase type of the number to set in the ncx_num_t struct
is_negif TRUE then number checked and saved is -1 * 'val'
Returns
status

◆ ncx_set_num_max()

void ncx_set_num_max ( ncx_num_t num,
ncx_btype_t  btyp 
)

Set a number to the maximum value for its type.

Parameters
numnumber to set
btypexpected data type

◆ ncx_set_num_min()

void ncx_set_num_min ( ncx_num_t num,
ncx_btype_t  btyp 
)

Set a number to the minimum value for its type.

Parameters
numnumber to set
btypexpected data type

◆ ncx_set_num_nan()

void ncx_set_num_nan ( ncx_num_t num,
ncx_btype_t  btyp 
)

Set a FP number to the Not a Number value.

Parameters
numnumber to set
btypexpected data type
Here is the caller graph for this function:

◆ ncx_set_num_one()

void ncx_set_num_one ( ncx_num_t num,
ncx_btype_t  btyp 
)

Set a number to one.

Parameters
numnumber to set
btypexpected data type
Here is the caller graph for this function:

◆ ncx_set_num_zero()

void ncx_set_num_zero ( ncx_num_t num,
ncx_btype_t  btyp 
)

Set a number to zero.

Parameters
numnumber to set
btypexpected data type
Here is the caller graph for this function:

◆ ncx_sprintf_num()

status_t ncx_sprintf_num ( xmlChar *  buff,
const ncx_num_t num,
ncx_btype_t  btyp,
uint32 *  len 
)

Sprintf a ncx_num_t contents.

Parameters
buffbuffer to write; NULL means just get length
numnumber to printf
btypnumber base type
[out]lenaddress of return length
  • *len number of bytes written (or would have been) to buff
Returns
status
Here is the call graph for this function:
Here is the caller graph for this function: