Skip to content

Commit a481b2b

Browse files
committed
Add binding for GHCJS
implement javascript versions under the assumption that engines where we run the code will have V8 compatibile implementation. NodeJS looks fine.
1 parent e4b7956 commit a481b2b

File tree

2 files changed

+94
-0
lines changed

2 files changed

+94
-0
lines changed

double-conversion.cabal

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,8 @@ library
7070
double-conversion/src/fast-dtoa.cc
7171
double-conversion/src/fixed-dtoa.cc
7272
double-conversion/src/strtod.cc
73+
js-sources:
74+
jsbits/hs-double-conversion.js
7375

7476
if os(windows)
7577
if arch(x86_64)

jsbits/hs-double-conversion.js

Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
1+
2+
var kToFixedLength =
3+
1 + /* DoubleToStringConverter::kMaxFixedDigitsBeforePoint*/ 60 +
4+
1 + /* DoubleToStringConverter::kMaxFixedDigitsAfterPoint*/ 60;
5+
6+
7+
var kToShortestLength = 26;
8+
var kToExponentialLength = /*DoubleToStringConverter::kMaxExponentialDigits*/ 120 + 8;
9+
var kToPrecisionLength = /*DoubleToStringConverter::kMaxPrecisionDigits*/ 120 + 7;
10+
11+
function h$_hs_ToShortestLength() {
12+
return kToShortestLength;
13+
}
14+
15+
function h$_hs_ToFixedLength()
16+
{
17+
return kToFixedLength;
18+
}
19+
20+
function h$_hs_ToExponentialLength()
21+
{
22+
return kToExponentialLength;
23+
}
24+
25+
function h$_hs_ToPrecisionLength()
26+
{
27+
return kToPrecisionLength;
28+
}
29+
30+
//--------------------
31+
32+
function h$_hs_Text_ToShortest(value, buf)
33+
{
34+
var conv = value.toString().replace("e+","e");
35+
Array.prototype.map.call(conv,function(c,i){ buf.u1[i]=c.charCodeAt(0)});
36+
return buf.len = conv.length;
37+
}
38+
39+
function h$_hs_ToShortest(value, buf)
40+
{
41+
var conv = value.toString().replace("e+","e");
42+
Array.prototype.map.call(conv,function(c,i){ buf.u8[i]=c.charCodeAt(0)});
43+
return buf.len = conv.length;
44+
}
45+
46+
//--------------------
47+
48+
function h$_hs_Text_ToFixed(value, buf, ndigits)
49+
{
50+
var conv = value.toFixed(Math.min(20,ndigits))+ "0".repeat(Math.max(0,ndigits - 20));
51+
Array.prototype.map.call(conv,function(c,i){ buf.u1[i]=c.charCodeAt(0)});
52+
return buf.len = conv.length;
53+
}
54+
55+
function h$_hs_ToFixed(value, buf, unused, ndigits)
56+
{
57+
var conv = value.toFixed(Math.min(20,ndigits))+ "0".repeat(Math.max(0,ndigits - 20));
58+
Array.prototype.map.call(conv,function(c,i){ buf.u8[i]=c.charCodeAt(0)});
59+
return buf.len = conv.length;
60+
}
61+
62+
//--------------------
63+
64+
function h$_hs_Text_ToExponential(value, buf, ndigits)
65+
{
66+
var conv = value.toExponential(ndigits).replace("e+","e");
67+
Array.prototype.map.call(conv,function(c,i){ buf.u1[i]=c.charCodeAt(0)});
68+
return buf.len = conv.length;
69+
}
70+
71+
function h$_hs_ToExponential(value, buf, unused, ndigits)
72+
{
73+
var conv = value.toExponential(ndigits).replace("e+","e");
74+
Array.prototype.map.call(conv,function(c,i){ buf.u8[i]=c.charCodeAt(0)});
75+
return buf.len = conv.length;
76+
}
77+
78+
//--------------------
79+
80+
function h$_hs_Text_ToPrecision(value, buf, ndigits)
81+
{
82+
var conv = value.toPrecision(Math.min(21,ndigits)) + "0".repeat(Math.max(0,ndigits - 21));
83+
Array.prototype.map.call(conv,function(c,i){ buf.u1[i]=c.charCodeAt(0)});
84+
return buf.len = conv.length;
85+
}
86+
87+
function h$_hs_ToPrecision(value, buf, unused, ndigits)
88+
{
89+
var conv = value.toPrecision(Math.min(21,ndigits))+ "0".repeat(Math.max(0,ndigits - 21));
90+
Array.prototype.map.call(conv,function(c,i){ buf.u8[i]=c.charCodeAt(0)});
91+
return buf.len = conv.length;
92+
}

0 commit comments

Comments
 (0)