omnomnum 0.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/ext/omnomnum/extconf.rb +51 -0
- data/ext/omnomnum/omnomnum/branchlut/branchlut.c +276 -0
- data/ext/omnomnum/omnomnum/branchlut/branchlut.h +14 -0
- data/ext/omnomnum/omnomnum/dtoa.c +68 -0
- data/ext/omnomnum/omnomnum/dtoa.h +39 -0
- data/ext/omnomnum/omnomnum/grisu2/diy_fp.h +61 -0
- data/ext/omnomnum/omnomnum/grisu2/double.h +121 -0
- data/ext/omnomnum/omnomnum/grisu2/fast_exponent.h +44 -0
- data/ext/omnomnum/omnomnum/grisu2/grisu2.c +120 -0
- data/ext/omnomnum/omnomnum/grisu2/grisu2.h +36 -0
- data/ext/omnomnum/omnomnum/grisu2/k_comp.h +32 -0
- data/ext/omnomnum/omnomnum/grisu2/powers.h +27 -0
- data/ext/omnomnum/omnomnum/grisu2/powers_ten_round64.h +36 -0
- data/ext/omnomnum/omnomnum/grisu2/prettify.h +76 -0
- data/ext/omnomnum/omnomnum/itoa.c +40 -0
- data/ext/omnomnum/omnomnum/itoa.h +40 -0
- data/ext/omnomnum/omnomnum/main.c +87 -0
- data/ext/omnomnum/omnomnum/omnomnum.c +208 -0
- data/ext/omnomnum/omnomnum/omnomnum.h +47 -0
- data/ext/omnomnum/omnomnum/parser.c +3445 -0
- data/ext/omnomnum/omnomnum/parser.h +130 -0
- data/ext/omnomnum/omnomnum/scan.c +55 -0
- data/ext/omnomnum/omnomnum/scan.h +68 -0
- data/ext/omnomnum/omnomnum/scanner.c +4332 -0
- data/ext/omnomnum/omnomnum/scanner.def.c +97 -0
- data/ext/omnomnum/omnomnum/scanner.def.h +105 -0
- data/ext/omnomnum/omnomnum/scanner.h +44 -0
- data/ext/omnomnum/omnomnum/sds.c +1278 -0
- data/ext/omnomnum/omnomnum/sds.h +280 -0
- data/ext/omnomnum/omnomnum/sdsalloc.h +43 -0
- data/ext/omnomnum/omnomnum/test/test_benchmark.c +107 -0
- data/ext/omnomnum/omnomnum/test/test_omnomnum.c +146 -0
- data/ext/omnomnum/omnomnum/test/test_omnomnum.h +6 -0
- data/ext/omnomnum/omnomnum/test/test_util.c +98 -0
- data/ext/omnomnum/omnomnum/util.c +84 -0
- data/ext/omnomnum/omnomnum/util.h +43 -0
- data/ext/omnomnum/ruby_omnomnum.c +96 -0
- data/ext/omnomnum/ruby_omnomnum.h +40 -0
- data/lib/omnomnum.rb +31 -0
- data/lib/omnomnum/omnomnum.so +0 -0
- data/lib/omnomnum/version.rb +32 -0
- metadata +114 -0
@@ -0,0 +1,61 @@
|
|
1
|
+
/*
|
2
|
+
Copyright (c) 2009 Florian Loitsch
|
3
|
+
|
4
|
+
Permission is hereby granted, free of charge, to any person
|
5
|
+
obtaining a copy of this software and associated documentation
|
6
|
+
files (the "Software"), to deal in the Software without
|
7
|
+
restriction, including without limitation the rights to use,
|
8
|
+
copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the
|
10
|
+
Software is furnished to do so, subject to the following
|
11
|
+
conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
|
18
|
+
OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
|
20
|
+
HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
|
21
|
+
WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
22
|
+
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
|
23
|
+
OTHER DEALINGS IN THE SOFTWARE.
|
24
|
+
*/
|
25
|
+
#pragma once
|
26
|
+
#include <stdint.h>
|
27
|
+
#include <assert.h>
|
28
|
+
|
29
|
+
typedef struct diy_fp_t {
|
30
|
+
uint64_t f;
|
31
|
+
int e;
|
32
|
+
} diy_fp_t;
|
33
|
+
|
34
|
+
static diy_fp_t minus(diy_fp_t x, diy_fp_t y) {
|
35
|
+
assert(x.e == y.e);
|
36
|
+
assert(x.f >= y.f);
|
37
|
+
diy_fp_t r = {.f = x.f - y.f, .e = x.e};
|
38
|
+
return r;
|
39
|
+
}
|
40
|
+
|
41
|
+
/*
|
42
|
+
static diy_fp_t minus(diy_fp_t x, diy_fp_t y) {
|
43
|
+
assert(x.e == y.e);
|
44
|
+
assert(x.f >= y.f);
|
45
|
+
diy_fp_t r = {.f = x.f - y.f, .e = x.e};
|
46
|
+
return r;
|
47
|
+
}
|
48
|
+
*/
|
49
|
+
|
50
|
+
static diy_fp_t multiply(diy_fp_t x, diy_fp_t y) {
|
51
|
+
uint64_t a,b,c,d,ac,bc,ad,bd,tmp,h;
|
52
|
+
diy_fp_t r; uint64_t M32 = 0xFFFFFFFF;
|
53
|
+
a = x.f >> 32; b = x.f & M32;
|
54
|
+
c = y.f >> 32; d = y.f & M32;
|
55
|
+
ac = a*c; bc = b*c; ad = a*d; bd = b*d;
|
56
|
+
tmp = (bd>>32) + (ad&M32) + (bc&M32);
|
57
|
+
tmp += 1U << 31; /// mult_round
|
58
|
+
r.f = ac+(ad>>32)+(bc>>32)+(tmp >>32);
|
59
|
+
r.e = x.e + y.e + 64;
|
60
|
+
return r;
|
61
|
+
}
|
@@ -0,0 +1,121 @@
|
|
1
|
+
/*
|
2
|
+
Copyright (c) 2009 Florian Loitsch
|
3
|
+
|
4
|
+
Permission is hereby granted, free of charge, to any person
|
5
|
+
obtaining a copy of this software and associated documentation
|
6
|
+
files (the "Software"), to deal in the Software without
|
7
|
+
restriction, including without limitation the rights to use,
|
8
|
+
copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the
|
10
|
+
Software is furnished to do so, subject to the following
|
11
|
+
conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
|
18
|
+
OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
|
20
|
+
HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
|
21
|
+
WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
22
|
+
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
|
23
|
+
OTHER DEALINGS IN THE SOFTWARE.
|
24
|
+
*/
|
25
|
+
#pragma once
|
26
|
+
|
27
|
+
#include "diy_fp.h"
|
28
|
+
#include "powers.h"
|
29
|
+
#include <stdlib.h>
|
30
|
+
#include <stdbool.h>
|
31
|
+
|
32
|
+
typedef union {
|
33
|
+
double d;
|
34
|
+
uint64_t n;
|
35
|
+
} converter_t;
|
36
|
+
|
37
|
+
static uint64_t double_to_uint64(double d) { converter_t tmp; tmp.d = d; return tmp.n; }
|
38
|
+
static double uint64_to_double(uint64_t d64) { converter_t tmp; tmp.n = d64; return tmp.d; }
|
39
|
+
|
40
|
+
#define DP_SIGNIFICAND_SIZE 52
|
41
|
+
#define DP_EXPONENT_BIAS (0x3FF + DP_SIGNIFICAND_SIZE)
|
42
|
+
#define DP_MIN_EXPONENT (-DP_EXPONENT_BIAS)
|
43
|
+
#define DP_EXPONENT_MASK 0x7FF0000000000000
|
44
|
+
#define DP_SIGNIFICAND_MASK 0x000FFFFFFFFFFFFF
|
45
|
+
#define DP_HIDDEN_BIT 0x0010000000000000
|
46
|
+
|
47
|
+
static diy_fp_t normalize_diy_fp(diy_fp_t in) {
|
48
|
+
diy_fp_t res = in;
|
49
|
+
/* Normalize now */
|
50
|
+
/* the original number could have been a denormal. */
|
51
|
+
while (! (res.f & DP_HIDDEN_BIT))
|
52
|
+
{
|
53
|
+
res.f <<= 1;
|
54
|
+
res.e--;
|
55
|
+
}
|
56
|
+
/* do the final shifts in one go. Don't forget the hidden bit (the '-1') */
|
57
|
+
res.f <<= (DIY_SIGNIFICAND_SIZE - DP_SIGNIFICAND_SIZE - 1);
|
58
|
+
res.e = res.e - (DIY_SIGNIFICAND_SIZE - DP_SIGNIFICAND_SIZE - 1);
|
59
|
+
return res;
|
60
|
+
}
|
61
|
+
|
62
|
+
static diy_fp_t double2diy_fp(double d) {
|
63
|
+
uint64_t d64 = double_to_uint64(d);
|
64
|
+
int biased_e = (d64 & DP_EXPONENT_MASK) >> DP_SIGNIFICAND_SIZE;
|
65
|
+
uint64_t significand = (d64 & DP_SIGNIFICAND_MASK);
|
66
|
+
diy_fp_t res;
|
67
|
+
if (biased_e != 0)
|
68
|
+
{
|
69
|
+
res.f = significand + DP_HIDDEN_BIT;
|
70
|
+
res.e = biased_e - DP_EXPONENT_BIAS;
|
71
|
+
} else {
|
72
|
+
res.f = significand;
|
73
|
+
res.e = DP_MIN_EXPONENT + 1;
|
74
|
+
}
|
75
|
+
return res;
|
76
|
+
}
|
77
|
+
|
78
|
+
static diy_fp_t normalize_boundary(diy_fp_t in) {
|
79
|
+
diy_fp_t res = in;
|
80
|
+
/* Normalize now */
|
81
|
+
/* the original number could have been a denormal. */
|
82
|
+
while (! (res.f & (DP_HIDDEN_BIT << 1)))
|
83
|
+
{
|
84
|
+
res.f <<= 1;
|
85
|
+
res.e--;
|
86
|
+
}
|
87
|
+
/* do the final shifts in one go. Don't forget the hidden bit (the '-1') */
|
88
|
+
res.f <<= (DIY_SIGNIFICAND_SIZE - DP_SIGNIFICAND_SIZE - 2);
|
89
|
+
res.e = res.e - (DIY_SIGNIFICAND_SIZE - DP_SIGNIFICAND_SIZE - 2);
|
90
|
+
return res;
|
91
|
+
}
|
92
|
+
|
93
|
+
static void normalized_boundaries(double d, diy_fp_t* out_m_minus, diy_fp_t* out_m_plus) {
|
94
|
+
diy_fp_t v = double2diy_fp(d);
|
95
|
+
diy_fp_t pl, mi;
|
96
|
+
bool significand_is_zero = v.f == DP_HIDDEN_BIT;
|
97
|
+
pl.f = (v.f << 1) + 1; pl.e = v.e - 1;
|
98
|
+
pl = normalize_boundary(pl);
|
99
|
+
if (significand_is_zero)
|
100
|
+
{
|
101
|
+
mi.f = (v.f << 2) - 1;
|
102
|
+
mi.e = v.e - 2;
|
103
|
+
} else {
|
104
|
+
mi.f = (v.f << 1) - 1;
|
105
|
+
mi.e = v.e - 1;
|
106
|
+
}
|
107
|
+
mi.f <<= mi.e - pl.e;
|
108
|
+
mi.e = pl.e;
|
109
|
+
*out_m_plus = pl;
|
110
|
+
*out_m_minus = mi;
|
111
|
+
}
|
112
|
+
|
113
|
+
static double random_double() {
|
114
|
+
uint64_t tmp = 0;
|
115
|
+
int i;
|
116
|
+
for (i = 0; i < 8; i++) {
|
117
|
+
tmp <<= 8;
|
118
|
+
tmp += rand() % 256;
|
119
|
+
}
|
120
|
+
return uint64_to_double(tmp);
|
121
|
+
}
|
@@ -0,0 +1,44 @@
|
|
1
|
+
/*
|
2
|
+
Copyright (c) 2009 Florian Loitsch
|
3
|
+
|
4
|
+
Permission is hereby granted, free of charge, to any person
|
5
|
+
obtaining a copy of this software and associated documentation
|
6
|
+
files (the "Software"), to deal in the Software without
|
7
|
+
restriction, including without limitation the rights to use,
|
8
|
+
copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the
|
10
|
+
Software is furnished to do so, subject to the following
|
11
|
+
conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
|
18
|
+
OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
|
20
|
+
HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
|
21
|
+
WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
22
|
+
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
|
23
|
+
OTHER DEALINGS IN THE SOFTWARE.
|
24
|
+
*/
|
25
|
+
#pragma once
|
26
|
+
|
27
|
+
static void fill_exponent(int K, char* buffer) {
|
28
|
+
int i = 0;
|
29
|
+
if (K < 0) {
|
30
|
+
buffer[i++] = '-';
|
31
|
+
K = -K;
|
32
|
+
}
|
33
|
+
if (K >= 100) {
|
34
|
+
buffer[i++] = '0' + K / 100; K %= 100;
|
35
|
+
buffer[i++] = '0' + K / 10; K %= 10;
|
36
|
+
buffer[i++] = '0' + K;
|
37
|
+
} else if (K >= 10) {
|
38
|
+
buffer[i++] = '0' + K / 10; K %= 10;
|
39
|
+
buffer[i++] = '0' + K;
|
40
|
+
} else {
|
41
|
+
buffer[i++] = '0' + K;
|
42
|
+
}
|
43
|
+
buffer[i] = '\0';
|
44
|
+
}
|
@@ -0,0 +1,120 @@
|
|
1
|
+
/*
|
2
|
+
Copyright (c) 2009 Florian Loitsch
|
3
|
+
|
4
|
+
Permission is hereby granted, free of charge, to any person
|
5
|
+
obtaining a copy of this software and associated documentation
|
6
|
+
files (the "Software"), to deal in the Software without
|
7
|
+
restriction, including without limitation the rights to use,
|
8
|
+
copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the
|
10
|
+
Software is furnished to do so, subject to the following
|
11
|
+
conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
|
18
|
+
OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
|
20
|
+
HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
|
21
|
+
WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
22
|
+
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
|
23
|
+
OTHER DEALINGS IN THE SOFTWARE.
|
24
|
+
*/
|
25
|
+
#include "diy_fp.h"
|
26
|
+
#include "k_comp.h"
|
27
|
+
#include "double.h"
|
28
|
+
#include "powers.h"
|
29
|
+
#include <stdbool.h>
|
30
|
+
#include <stdio.h>
|
31
|
+
#include "grisu2.h"
|
32
|
+
#include <inttypes.h>
|
33
|
+
|
34
|
+
#define HUMAN_READABLE
|
35
|
+
|
36
|
+
bool fill_double(double v, char* buffer) {
|
37
|
+
if (v == 0) {
|
38
|
+
strcpy(buffer, "0.0");
|
39
|
+
return 1;
|
40
|
+
} else {
|
41
|
+
if (v < 0) {
|
42
|
+
*buffer++ = '-';
|
43
|
+
v = -v;
|
44
|
+
}
|
45
|
+
|
46
|
+
int length, K;
|
47
|
+
grisu2(v, buffer, &length, &K);
|
48
|
+
#ifndef HUMAN_READABLE
|
49
|
+
buffer[length] = 'e';
|
50
|
+
fill_exponent(K, &buffer[length+1]);
|
51
|
+
#else
|
52
|
+
prettify_string(buffer, 0, length, K);
|
53
|
+
#endif
|
54
|
+
return 1;
|
55
|
+
}
|
56
|
+
}
|
57
|
+
|
58
|
+
#define TEN9 1000000000
|
59
|
+
|
60
|
+
void grisu_round(char* buffer, int len,
|
61
|
+
uint64_t delta, uint64_t rest,
|
62
|
+
uint64_t ten_kappa, uint64_t wp_w) {
|
63
|
+
while (rest < wp_w &&
|
64
|
+
delta - rest >= ten_kappa &&
|
65
|
+
(rest + ten_kappa < wp_w || /// closer
|
66
|
+
wp_w - rest > rest+ten_kappa - wp_w))
|
67
|
+
{
|
68
|
+
buffer[len-1]--; rest += ten_kappa;
|
69
|
+
}
|
70
|
+
}
|
71
|
+
|
72
|
+
void digit_gen(diy_fp_t W, diy_fp_t Mp, diy_fp_t delta,
|
73
|
+
char* buffer, int* len, int* K) {
|
74
|
+
uint32_t div; int d,kappa; diy_fp_t one, wp_w;
|
75
|
+
wp_w = minus(Mp, W);
|
76
|
+
one.f = ((uint64_t) 1) << -Mp.e; one.e = Mp.e;
|
77
|
+
uint32_t p1 = Mp.f >> -one.e; /// Mp_cut
|
78
|
+
uint64_t p2 = Mp.f & (one.f - 1);
|
79
|
+
*len = 0; kappa = 10; div = TEN9;
|
80
|
+
while (kappa > 0) {
|
81
|
+
d = p1 / div;
|
82
|
+
if (d || *len) buffer[(*len)++] = '0' + d; /// Mp_inv1
|
83
|
+
p1 %= div; kappa--;
|
84
|
+
uint64_t tmp = (((uint64_t)p1)<<-one.e)+p2;
|
85
|
+
if (tmp <= delta.f) { /// Mp_delta
|
86
|
+
*K += kappa;
|
87
|
+
grisu_round(buffer, *len, delta.f, tmp, ((uint64_t)div) << -one.e, wp_w.f);
|
88
|
+
return;
|
89
|
+
}
|
90
|
+
div /= 10;
|
91
|
+
}
|
92
|
+
uint64_t unit = 1;
|
93
|
+
while (1) {
|
94
|
+
p2 *= 10; delta.f *= 10; unit *= 10;
|
95
|
+
d = p2 >> -one.e;
|
96
|
+
if (d || *len) buffer[(*len)++] = '0' + d;
|
97
|
+
p2 &= one.f - 1; kappa--;
|
98
|
+
if (p2 < delta.f) {
|
99
|
+
*K += kappa;
|
100
|
+
grisu_round(buffer, *len, delta.f, p2, one.f, wp_w.f*unit);
|
101
|
+
return;
|
102
|
+
}
|
103
|
+
}
|
104
|
+
}
|
105
|
+
|
106
|
+
void grisu2(double v, char* buffer, int* length, int* K) {
|
107
|
+
diy_fp_t w_m, w_p;
|
108
|
+
int q = 64, alpha = -59, gamma = -56; int pos;
|
109
|
+
normalized_boundaries(v, &w_m, &w_p);
|
110
|
+
diy_fp_t w = normalize_diy_fp(double2diy_fp(v));
|
111
|
+
int mk = k_comp(w_p.e + q, alpha, gamma);
|
112
|
+
diy_fp_t c_mk = cached_power(mk);
|
113
|
+
diy_fp_t W = multiply(w, c_mk);
|
114
|
+
diy_fp_t Wp = multiply(w_p, c_mk);
|
115
|
+
diy_fp_t Wm = multiply(w_m, c_mk);
|
116
|
+
Wm.f++; Wp.f--;
|
117
|
+
diy_fp_t delta = minus(Wp, Wm);
|
118
|
+
*K = -mk;
|
119
|
+
digit_gen(W, Wp, delta, buffer, length, K);
|
120
|
+
}
|
@@ -0,0 +1,36 @@
|
|
1
|
+
#ifndef GRISU2_H
|
2
|
+
#define GRISU2_H
|
3
|
+
|
4
|
+
/*
|
5
|
+
Copyright (c) 2009 Florian Loitsch
|
6
|
+
|
7
|
+
Permission is hereby granted, free of charge, to any person
|
8
|
+
obtaining a copy of this software and associated documentation
|
9
|
+
files (the "Software"), to deal in the Software without
|
10
|
+
restriction, including without limitation the rights to use,
|
11
|
+
copy, modify, merge, publish, distribute, sublicense, and/or sell
|
12
|
+
copies of the Software, and to permit persons to whom the
|
13
|
+
Software is furnished to do so, subject to the following
|
14
|
+
conditions:
|
15
|
+
|
16
|
+
The above copyright notice and this permission notice shall be
|
17
|
+
included in all copies or substantial portions of the Software.
|
18
|
+
|
19
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
20
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
|
21
|
+
OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
22
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
|
23
|
+
HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
|
24
|
+
WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
25
|
+
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
|
26
|
+
OTHER DEALINGS IN THE SOFTWARE.
|
27
|
+
*/
|
28
|
+
#pragma once
|
29
|
+
#include "prettify.h"
|
30
|
+
#include "fast_exponent.h"
|
31
|
+
#include <stdbool.h>
|
32
|
+
|
33
|
+
void grisu2(double v, char* buffer, int* length, int* K);
|
34
|
+
bool fill_double(double v, char* buffer);
|
35
|
+
|
36
|
+
#endif // GRISU2_H
|
@@ -0,0 +1,32 @@
|
|
1
|
+
/*
|
2
|
+
Copyright (c) 2009 Florian Loitsch
|
3
|
+
|
4
|
+
Permission is hereby granted, free of charge, to any person
|
5
|
+
obtaining a copy of this software and associated documentation
|
6
|
+
files (the "Software"), to deal in the Software without
|
7
|
+
restriction, including without limitation the rights to use,
|
8
|
+
copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the
|
10
|
+
Software is furnished to do so, subject to the following
|
11
|
+
conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
|
18
|
+
OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
|
20
|
+
HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
|
21
|
+
WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
22
|
+
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
|
23
|
+
OTHER DEALINGS IN THE SOFTWARE.
|
24
|
+
*/
|
25
|
+
#pragma once
|
26
|
+
#include <math.h>
|
27
|
+
|
28
|
+
#define D_1_LOG2_10 0.30102999566398114 // 1 / lg(10)
|
29
|
+
|
30
|
+
static int k_comp(int e, int alpha, int gamma) {
|
31
|
+
return ceil((alpha-e+63) * D_1_LOG2_10);
|
32
|
+
}
|
@@ -0,0 +1,27 @@
|
|
1
|
+
/*
|
2
|
+
Copyright (c) 2009 Florian Loitsch
|
3
|
+
|
4
|
+
Permission is hereby granted, free of charge, to any person
|
5
|
+
obtaining a copy of this software and associated documentation
|
6
|
+
files (the "Software"), to deal in the Software without
|
7
|
+
restriction, including without limitation the rights to use,
|
8
|
+
copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the
|
10
|
+
Software is furnished to do so, subject to the following
|
11
|
+
conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
|
18
|
+
OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
|
20
|
+
HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
|
21
|
+
WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
22
|
+
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
|
23
|
+
OTHER DEALINGS IN THE SOFTWARE.
|
24
|
+
*/
|
25
|
+
#pragma once
|
26
|
+
#include "diy_fp.h"
|
27
|
+
#include "powers_ten_round64.h"
|