blob: 8a1053bcc31f5b78939cda059871a30e793f2fb0 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
|
#include <errno.h>
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <stdint.h>
#include <assert.h>
#include <math.h>
#include "export.h"
#define PARSE_FP(fp_type, func, huge_val) \
fp_type parse_ ## fp_type (Pointer repr, int *status) {\
char *f = (char*)repr;\
char *tmp;\
fp_type result; \
int saved_errno = errno;\
\
errno = 0;\
result = func(f, &tmp);\
\
if (errno == ERANGE) {\
if (result == huge_val)\
*status = 1;\
else\
*status = -1;\
}\
errno = saved_errno;\
\
if (f + strlen(f) != tmp)\
*status = 2;\
return result;\
}
PARSE_FP(float, strtof, HUGE_VALF)
PARSE_FP(double, strtod, HUGE_VAL)
int64_t conv_word64_to_int64(uint64_t word) { return word; }
uint64_t conv_int64_to_word64(int64_t i) { return i; }
int32_t conv_word64_to_int32(uint64_t word) { return word; }
uint64_t conv_int32_to_word64(int32_t i) { return i; }
|