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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
|
--- goffice/math/go-ryu.c 2023-05-20 20:02:02.000000000 -0300
+++ goffice/math/go-ryu.c.patched 2023-12-27 19:28:35.623167312 -0400
@@ -3,55 +3,8 @@
#define bool int
#include "go-ryu.h"
-// File ryu.h imported from ryu
-// Copyright 2018 Ulf Adams
-//
-// The contents of this file may be used under the terms of the Apache License,
-// Version 2.0.
-//
-// (See accompanying file LICENSE-Apache or copy at
-// http://www.apache.org/licenses/LICENSE-2.0)
-//
-// Alternatively, the contents of this file may be used under the terms of
-// the Boost Software License, Version 1.0.
-// (See accompanying file LICENSE-Boost or copy at
-// https://www.boost.org/LICENSE_1_0.txt)
-//
-// Unless required by applicable law or agreed to in writing, this software
-// is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
-// KIND, either express or implied.
-#ifndef RYU_H
-#define RYU_H
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
#include <inttypes.h>
-int go_ryu_d2s_buffered_n(double f, char* result);
-void go_ryu_d2s_buffered(double f, char* result);
-char* go_ryu_d2s(double f);
-
-int go_ryu_f2s_buffered_n(float f, char* result);
-void go_ryu_f2s_buffered(float f, char* result);
-char* go_ryu_f2s(float f);
-
-int go_ryu_d2fixed_buffered_n(double d, uint32_t precision, char* result);
-void go_ryu_d2fixed_buffered(double d, uint32_t precision, char* result);
-char* go_ryu_d2fixed(double d, uint32_t precision);
-
-int go_ryu_d2exp_buffered_n(double d, uint32_t precision, char* result);
-void go_ryu_d2exp_buffered(double d, uint32_t precision, char* result);
-char* go_ryu_d2exp(double d, uint32_t precision);
-
-#ifdef __cplusplus
-}
-#endif
-
-#endif // RYU_H
-// End of file ryu.h imported from ryu
-
// File common.h imported from ryu
// Copyright 2018 Ulf Adams
//
@@ -1242,20 +1195,25 @@
return to_chars(v, ieeeSign, result);
}
-void go_ryu_d2s_buffered(double f, char* result) {
+#if 0
+static void go_ryu_d2s_buffered(double f, char* result) {
const int index = go_ryu_d2s_buffered_n(f, result);
// Terminate the string.
result[index] = '\0';
}
+#endif
-char* go_ryu_d2s(double f) {
+#if 0
+static char* go_ryu_d2s(double f) {
char* const result = (char*) malloc(25);
go_ryu_d2s_buffered(f, result);
return result;
}
+#endif
// End of file d2s.c imported from ryu
+#ifdef GOFFICE_WITH_LONG_DOUBLE
// File ryu_generic_128.h imported from ryu
// Copyright 2018 Ulf Adams
//
@@ -1303,16 +1261,20 @@
bool sign;
};
-struct floating_decimal_128 go_ryu_float_to_fd128(float f);
-struct floating_decimal_128 go_ryu_double_to_fd128(double d);
+#if 0
+static struct floating_decimal_128 go_ryu_float_to_fd128(float f);
+#endif
+#if 0
+static struct floating_decimal_128 go_ryu_double_to_fd128(double d);
+#endif
// According to wikipedia (https://en.wikipedia.org/wiki/Long_double), this likely only works on
// x86 with specific compilers (clang?). May need an ifdef.
-struct floating_decimal_128 go_ryu_long_double_to_fd128(long double d);
+static struct floating_decimal_128 go_ryu_long_double_to_fd128(long double d);
// Converts the given binary floating point number to the shortest decimal floating point number
// that still accurately represents it.
-struct floating_decimal_128 go_ryu_generic_binary_to_decimal(
+static struct floating_decimal_128 go_ryu_generic_binary_to_decimal(
const __uint128_t bits, const uint32_t mantissaBits, const uint32_t exponentBits, const bool explicitLeadingBit);
// Converts the given decimal floating point number to a string, writing to result, and returning
@@ -1322,7 +1284,7 @@
// Maximal char buffer requirement:
// sign + mantissa digits + decimal dot + 'E' + exponent sign + exponent digits
// = 1 + 39 + 1 + 1 + 1 + 10 = 53
-int go_ryu_generic_to_chars(const struct floating_decimal_128 v, char* const result);
+static int go_ryu_generic_to_chars(const struct floating_decimal_128 v, char* const result);
#ifdef __cplusplus
}
@@ -1330,7 +1292,9 @@
#endif // RYU_GENERIC_128_H
// End of file ryu_generic_128.h imported from ryu
+#endif // GOFFICE_WITH_LONG_DOUBLE
+#ifdef GOFFICE_WITH_LONG_DOUBLE
// File generic_128.h imported from ryu
// Copyright 2018 Ulf Adams
//
@@ -1852,7 +1816,9 @@
#endif // RYU_GENERIC128_H
// End of file generic_128.h imported from ryu
+#endif // GOFFICE_WITH_LONG_DOUBLE
+#ifdef GOFFICE_WITH_LONG_DOUBLE
// File generic_128.c imported from ryu
// Copyright 2018 Ulf Adams
//
@@ -1903,25 +1869,29 @@
#define FLOAT_MANTISSA_BITS 23
#define FLOAT_EXPONENT_BITS 8
-struct floating_decimal_128 go_ryu_float_to_fd128(float f) {
+#if 0
+static struct floating_decimal_128 go_ryu_float_to_fd128(float f) {
uint32_t bits = 0;
memcpy(&bits, &f, sizeof(float));
return go_ryu_generic_binary_to_decimal(bits, FLOAT_MANTISSA_BITS, FLOAT_EXPONENT_BITS, false);
}
+#endif
#define DOUBLE_MANTISSA_BITS 52
#define DOUBLE_EXPONENT_BITS 11
-struct floating_decimal_128 go_ryu_double_to_fd128(double d) {
+#if 0
+static struct floating_decimal_128 go_ryu_double_to_fd128(double d) {
uint64_t bits = 0;
memcpy(&bits, &d, sizeof(double));
return go_ryu_generic_binary_to_decimal(bits, DOUBLE_MANTISSA_BITS, DOUBLE_EXPONENT_BITS, false);
}
+#endif
#define LONG_DOUBLE_MANTISSA_BITS 64
#define LONG_DOUBLE_EXPONENT_BITS 15
-struct floating_decimal_128 go_ryu_long_double_to_fd128(long double d) {
+static struct floating_decimal_128 go_ryu_long_double_to_fd128(long double d) {
uint128_t bits = 0;
memcpy(&bits, &d, sizeof(long double));
#ifdef RYU_DEBUG
@@ -1934,7 +1904,7 @@
return go_ryu_generic_binary_to_decimal(bits, LONG_DOUBLE_MANTISSA_BITS, LONG_DOUBLE_EXPONENT_BITS, true);
}
-struct floating_decimal_128 go_ryu_generic_binary_to_decimal(
+static struct floating_decimal_128 go_ryu_generic_binary_to_decimal(
const uint128_t bits, const uint32_t mantissaBits, const uint32_t exponentBits, const bool explicitLeadingBit) {
#ifdef RYU_DEBUG
printf("IN=");
@@ -2147,7 +2117,7 @@
return fd.sign + 8;
}
-int go_ryu_generic_to_chars(const struct floating_decimal_128 v, char* const result) {
+static int go_ryu_generic_to_chars(const struct floating_decimal_128 v, char* const result) {
if (v.exponent == FD128_EXCEPTIONAL_EXPONENT) {
return copy_special_strl(result, v);
}
@@ -2200,9 +2170,12 @@
return index;
}
// End of file generic_128.c imported from ryu
+#endif // GOFFICE_WITH_LONG_DOUBLE
+#ifdef GOFFICE_WITH_LONG_DOUBLE
int go_ryu_ld2s_buffered_n (long double d, char *dst) {
struct floating_decimal_128 fd128 = go_ryu_long_double_to_fd128(d);
return go_ryu_generic_to_chars(fd128, dst);
}
+#endif
|