Marc-André Lureau <marcandre.lur...@gmail.com> writes: > Hi > > On Thu, Jun 1, 2017 at 6:10 PM Markus Armbruster <arm...@redhat.com> wrote: > >> Marc-André Lureau <marcandre.lur...@redhat.com> writes: >> >> > Suggested by Markus Armbruster: >> > >> > We should systematically cover the integers, in particular the >> > boundaries (because that's where bugs like to hide): >> > >> > * Integers in [-2^63,0) can be visited with visit_type_int() and >> > visit_type_number(). >> > >> > * Integers in [0,2^63) can be visited with visit_type_int(), >> > visit_type_uint64() and visit_type_number(). >> > >> > * Integers in [2^63,2^64) can be visited with visit_type_uint64() and >> > visit_type_number(). >> > >> > * Integers outside [-2^63,2^53) can be visited with visit_type_number(). >> > >> > In any case, visit_type_number() loses precision beyond 53 bits. >> > >> > Signed-off-by: Marc-André Lureau <marcandre.lur...@redhat.com> [...] >> > @@ -260,6 +272,26 @@ static void >> > test_visitor_in_number(TestInputVisitorData *data, >> > g_assert_cmpfloat(res, ==, value); >> > } >> > >> > +static void test_visitor_in_large_number(TestInputVisitorData *data, >> > + const void *unused) >> > +{ >> > + Error *err = NULL; >> > + double res = 0; >> > + int64_t i64; >> > + uint64_t u64; >> > + Visitor *v; >> > + >> > + v = visitor_input_test_init(data, "-18446744073709551616"); /* -2^64 >> > */ >> > + >> > + visit_type_number(v, NULL, &res, &error_abort); >> >> Shouldn't we check res has the expected value? >> >> > Is the precision loss during conversion going to be the same on all archs?
Yes. Precision is 53 bits on all hosts that matter, because double is IEEE 754 / IEC 60559 double precision on all hosts that matter. For pedantic portability, you may guard with #ifdef __STDC_IEC_559__. ISO/IEC 9899 §6.8.10 Predefined macro names: __STDC_IEC_559__ The integer constant 1, intended to indicate conformance to the specifications in annex F (IEC 60559 floating-point arithmetic). Annex F (normative) section F.2 Types: -- The double type matches the IEC 60559 double format. I wouldn't bother.