Skip to content

Commit 95a2cce

Browse files
committed
[GR-46490] Disable unsupported c builtin FLT_ROUNDS
PullRequest: graalpython/2818
2 parents 32f000b + a64eb80 commit 95a2cce

File tree

2 files changed

+21
-0
lines changed
  • graalpython
    • com.oracle.graal.python.cext/src
    • com.oracle.graal.python.test/src/tests/cpyext

2 files changed

+21
-0
lines changed

graalpython/com.oracle.graal.python.cext/src/dtoa.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -312,6 +312,8 @@ typedef union { double d; ULong L[2]; } U;
312312
#endif
313313
#endif /*Flt_Rounds*/
314314

315+
#undef Flt_Rounds // GR-46522
316+
#define Flt_Rounds 1
315317
#define Rounding Flt_Rounds
316318

317319
#define Big0 (Frac_mask1 | Exp_msk1*(DBL_MAX_EXP+Bias-1))

graalpython/com.oracle.graal.python.test/src/tests/cpyext/test_float.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -185,3 +185,22 @@ def test_PyOS_double_to_string(self):
185185
assert tester.PyOS_double_to_string_test(174.426353) == '174.426353'
186186
assert tester.PyOS_double_to_string_test(151.074362) == '151.074362'
187187
assert tester.PyOS_double_to_string_test(190.08) == '190.080000'
188+
189+
def test_PyOS_string_to_double(self):
190+
TestPyOS_String_To_Double = CPyExtType("TestPyOS_String_To_Double",
191+
'''
192+
static PyObject* testPyOS_Str_to_D(PyObject* self, PyObject *str) {
193+
char *endptr;
194+
const char *s = (char *) PyUnicode_AsUTF8(str);
195+
double ret = PyOS_string_to_double(s, &endptr, NULL);
196+
if (PyErr_Occurred()) {
197+
return NULL;
198+
}
199+
return PyFloat_FromDouble(ret);
200+
}
201+
''',
202+
tp_methods='{"PyOS_string_to_double_test", (PyCFunction)testPyOS_Str_to_D, METH_O, ""}',
203+
)
204+
tester = TestPyOS_String_To_Double()
205+
assert tester.PyOS_string_to_double_test('5') == float(5)
206+
assert tester.PyOS_string_to_double_test('150.604459') == float(150.604459)

0 commit comments

Comments
 (0)