1 /*
2 * Copyright (C) 2018 Alexander Borisov
3 *
4 * Author: Alexander Borisov <borisov@lexbor.com>
5 */
6
7 #ifndef LEXBOR_CONV_H
8 #define LEXBOR_CONV_H
9
10 #ifdef __cplusplus
11 extern "C" {
12 #endif
13
14
15 #include "lexbor/core/base.h"
16
17
18 LXB_API size_t
19 lexbor_conv_float_to_data(double num, lxb_char_t *buf, size_t len);
20
21 LXB_API size_t
22 lexbor_conv_long_to_data(long num, lxb_char_t *buf, size_t len);
23
24 LXB_API size_t
25 lexbor_conv_int64_to_data(int64_t num, lxb_char_t *buf, size_t len);
26
27 LXB_API double
28 lexbor_conv_data_to_double(const lxb_char_t **start, size_t len);
29
30 LXB_API unsigned long
31 lexbor_conv_data_to_ulong(const lxb_char_t **data, size_t length);
32
33 LXB_API long
34 lexbor_conv_data_to_long(const lxb_char_t **data, size_t length);
35
36 LXB_API unsigned
37 lexbor_conv_data_to_uint(const lxb_char_t **data, size_t length);
38
39 LXB_API size_t
40 lexbor_conv_dec_to_hex(uint32_t number, lxb_char_t *out, size_t length);
41
42 lxb_inline long
lexbor_conv_double_to_long(double number)43 lexbor_conv_double_to_long(double number)
44 {
45 if (number > (double) LONG_MAX) {
46 return LONG_MAX;
47 }
48
49 if (number < (double) LONG_MIN) {
50 return -LONG_MAX;
51 }
52
53 return (long) number;
54 }
55
56
57 #ifdef __cplusplus
58 } /* extern "C" */
59 #endif
60
61 #endif /* LEXBOR_CONV_H */
62