yumapro  24.10-2
YumaPro SDK
Loading...
Searching...
No Matches
ncx_num.h
Go to the documentation of this file.
1/*
2 * Copyright (c) 2008 - 2012, Andy Bierman, All Rights Reserved.
3 * Copyright (c) 2012 - 2021, YumaWorks, Inc., All Rights Reserved.
4 *
5 * Unless required by applicable law or agreed to in writing,
6 * software distributed under the License is distributed on an
7 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
8 * KIND, either express or implied. See the License for the
9 * specific language governing permissions and limitations
10 * under the License.
11 */
12#ifndef _H_ncx_num
13#define _H_ncx_num
14
15/* FILE: ncx_num.h
16*********************************************************************
17* *
18* P U R P O S E *
19* *
20*********************************************************************/
21
27/*********************************************************************
28* *
29* C H A N G E H I S T O R Y *
30* *
31*********************************************************************
32
33date init comment
34----------------------------------------------------------------------
3517-feb-10 abb Begun; split out from ncx.c
36*/
37
38#include <xmlstring.h>
39
40#ifndef _H_dlq
41#include "dlq.h"
42#endif
43
44#ifndef _H_ncxtypes
45#include "ncxtypes.h"
46#endif
47
48#ifndef _H_tk
49#include "tk.h"
50#endif
51
52#ifndef _H_typ
53#include "typ.h"
54#endif
55
56#ifndef _H_val
57#include "val.h"
58#endif
59
60#ifndef _H_xmlns
61#include "xmlns.h"
62#endif
63
64#ifndef _H_yang
65#include "yang.h"
66#endif
67
68#ifdef __cplusplus
69extern "C" {
70#endif
71
72/********************************************************************
73* *
74* F U N C T I O N S *
75* *
76*********************************************************************/
77
87#define NCX_MAX_DEC64_DIGITS 18
88
94extern void
96
97
109extern void
111 ncx_num_t *num);
112
113
127extern int32
128 ncx_compare_nums (const ncx_num_t *num1,
129 const ncx_num_t *num2,
130 ncx_btype_t btyp);
131
132
139extern void
141 ncx_btype_t btyp);
142
143
150extern void
152 ncx_btype_t btyp);
153
154
161extern void
163 ncx_btype_t btyp);
164
165
172extern void
174 ncx_btype_t btyp);
175
176
183extern void
185 ncx_btype_t btyp);
186
187
196extern boolean
198 ncx_btype_t btyp);
199
200
209extern boolean
210 ncx_num_zero (const ncx_num_t *num,
211 ncx_btype_t btyp);
212
213
227extern status_t
228 ncx_convert_num (const xmlChar *numstr,
229 ncx_numfmt_t numfmt,
230 ncx_btype_t btyp,
231 ncx_num_t *val);
232
233
246extern status_t
247 ncx_convert_dec64 (const xmlChar *numstr,
248 ncx_numfmt_t numfmt,
249 uint8 digits,
250 ncx_num_t *val);
251
252
253
276extern status_t
277 ncx_convert_cbor_dec64 (int64 mantissa,
278 int64 basenum,
279 uint8 digits,
280 ncx_num_t *val);
281
282
283
293extern status_t
294 ncx_decode_num (const xmlChar *numstr,
295 ncx_btype_t btyp,
296 ncx_num_t *retnum);
297
298
310extern status_t
311 ncx_decode_num_ex (const xmlChar *numstr,
312 ncx_btype_t btyp,
313 ncx_num_t *retnum,
314 typ_def_t *typdef);
315
316
326extern status_t
327 ncx_decode_dec64 (const xmlChar *numstr,
328 uint8 digits,
329 ncx_num_t *retnum);
330
331
348extern status_t
349 ncx_copy_num (const ncx_num_t *num1,
350 ncx_num_t *num2,
351 ncx_btype_t btyp);
352
353
371extern status_t
372 ncx_cast_num (const ncx_num_t *num1,
373 ncx_btype_t btyp1,
374 ncx_num_t *num2,
375 ncx_btype_t btyp2);
376
377
395extern status_t
396 ncx_num_floor (const ncx_num_t *num1,
397 ncx_num_t *num2,
398 ncx_btype_t btyp);
399
400
418extern status_t
419 ncx_num_ceiling (const ncx_num_t *num1,
420 ncx_num_t *num2,
421 ncx_btype_t btyp);
422
423
441extern status_t
442 ncx_round_num (const ncx_num_t *num1,
443 ncx_num_t *num2,
444 ncx_btype_t btyp);
445
446
462extern boolean
463 ncx_num_is_integral (const ncx_num_t *num,
464 ncx_btype_t btyp);
465
466
475extern int64
476 ncx_cvt_to_int64 (const ncx_num_t *num,
477 ncx_btype_t btyp);
478
479
489extern ncx_numfmt_t
490 ncx_get_numfmt (const xmlChar *numstr);
491
492
500extern void
501 ncx_printf_num (const ncx_num_t *num,
502 ncx_btype_t btyp,
503 log_debug_t level);
504
505
514extern void
515 ncx_printf_num_ex (const ncx_num_t *num,
516 ncx_btype_t btyp,
517 log_debug_t level,
518 FILE *overrideOut);
519
520
527extern void
528 ncx_alt_printf_num (const ncx_num_t *num,
529 ncx_btype_t btyp);
530
531
538extern void
540 ncx_btype_t btyp);
541
542
553extern status_t
554 ncx_sprintf_num (xmlChar *buff,
555 const ncx_num_t *num,
556 ncx_btype_t btyp,
557 uint32 *len);
558
559
569extern boolean
570 ncx_is_min (const ncx_num_t *num,
571 ncx_btype_t btyp);
572
573
583extern boolean
584 ncx_is_max (const ncx_num_t *num,
585 ncx_btype_t btyp);
586
587
600extern status_t
602 ncx_btype_t btyp,
603 ncx_num_t *val);
604
605
617extern status_t
619 uint8 digits,
620 ncx_num_t *val);
621
622
629extern int64
630 ncx_get_dec64_base (const ncx_num_t *num);
631
632
639extern int64
641
642
643
656extern status_t
658 uint64 val,
659 ncx_btype_t btyp,
660 boolean is_neg);
661
662
666#ifdef __cplusplus
667} /* end extern 'C' */
668#endif
669
670#endif /* _H_ncx_num */
dlq provides general double-linked list and queue support:
log_debug_t
The debug level enumerations used in util/log.c.
Definition: log.h:348
status_t
global error return code
Definition: status_enum.h:210
ncx_numfmt_t
Enumeration of number format types.
Definition: ncxtypes.h:497
ncx_btype_t
enumeration of the built-in NCX types These types cannot be overridden and cannot be imported
Definition: ncxtypes.h:213
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.
Definition: ncx_num.c:609
boolean ncx_num_zero(const ncx_num_t *num, ncx_btype_t btyp)
Compare a ncx_num_t to zero.
Definition: ncx_num.c:643
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.
Definition: ncx_num.c:2406
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.
Definition: ncx_num.c:1022
void ncx_set_num_nan(ncx_num_t *num, ncx_btype_t btyp)
Set a FP number to the Not a Number value.
Definition: ncx_num.c:576
status_t ncx_decode_dec64(const xmlChar *numstr, uint8 digits, ncx_num_t *retnum)
Handle some sort of decimal64 number string (NCX_BT_DECIMAL64)
Definition: ncx_num.c:1579
void ncx_set_num_one(ncx_num_t *num, ncx_btype_t btyp)
Set a number to one.
Definition: ncx_num.c:480
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.
Definition: ncx_num.c:2864
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.
Definition: ncx_num.c:186
int64 ncx_cvt_to_int64(const ncx_num_t *num, ncx_btype_t btyp)
Convert a number to an integer64; Use rounding for float64.
Definition: ncx_num.c:2299
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.
Definition: ncx_num.c:1645
status_t ncx_sprintf_num(xmlChar *buff, const ncx_num_t *num, ncx_btype_t btyp, uint32 *len)
Sprintf a ncx_num_t contents.
Definition: ncx_num.c:2543
ncx_numfmt_t ncx_get_numfmt(const xmlChar *numstr)
Get the number format of the specified string.
Definition: ncx_num.c:2358
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.
Definition: ncx_num.c:2502
void ncx_init_num(ncx_num_t *num)
Init a ncx_num_t struct.
Definition: ncx_num.c:161
void ncx_set_num_max(ncx_num_t *num, ncx_btype_t btyp)
Set a number to the maximum value for its type.
Definition: ncx_num.c:418
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.
Definition: ncx_num.c:2468
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.
Definition: ncx_num.c:2805
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.
Definition: ncx_num.c:2162
int64 ncx_get_dec64_fraction(const ncx_num_t *num)
Get the fraction part of a decimal64 number.
Definition: ncx_num.c:3008
void ncx_set_num_zero(ncx_num_t *num, ncx_btype_t btyp)
Set a number to zero.
Definition: ncx_num.c:528
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.
Definition: ncx_num.c:695
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.
Definition: ncx_num.c:1709
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.
Definition: ncx_num.c:2236
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)
Definition: ncx_num.c:2426
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.
Definition: ncx_num.c:1280
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.
Definition: ncx_num.c:236
void ncx_set_num_min(ncx_num_t *num, ncx_btype_t btyp)
Set a number to the minimum value for its type.
Definition: ncx_num.c:360
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.
Definition: ncx_num.c:2923
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.
Definition: ncx_num.c:2084
status_t ncx_decode_num(const xmlChar *numstr, ncx_btype_t btyp, ncx_num_t *retnum)
Handle some sort of number string.
Definition: ncx_num.c:1486
int64 ncx_get_dec64_base(const ncx_num_t *num)
Get the base part of a decimal64 number.
Definition: ncx_num.c:2978
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.
Definition: ncx_num.c:1510
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.
Definition: ncx_num.c:2750
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.
Definition: ncx_num.c:3040
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.
Definition: ncx_num.c:2007
YANG module data structures Many internal representations of YANG module constructs.
token parsing chain (main parser control block)
Definition: tk.h:415
Discriminated union for all data typedefs.
Definition: typ.h:458
NCX Syntax Token Handler.
Parameter Type Handler.
union of all the basic number types if float not supported, then it is stored as an int64
Definition: ncxtypes.h:784
Value Node Basic Support.
XML namespace support.
YANG Module parser utilities.