Re: mini-gmp mpz_{get,set}_d not fully compatible with GMP

2018-03-13 Thread Niels Möller
Vincent Lefevre writes: > More than an order issue, this is undefined behavior. In C11: > > 5.1.2.4 Multi-threaded executions and data races > >4 Two expression evaluations conflict if one of them modifies a > memory location and the other one reads or modifies the

Re: mini-gmp mpz_{get,set}_d not fully compatible with GMP

2018-03-13 Thread Torbjörn Granlund
Vincent Lefevre writes: On 2018-03-12 18:53:37 +0100, Marco Bodrato wrote: > double > mpz_get_d (const mpz_t u) > { > static int c = 0; > static int __initialized = 0; > > if (__initialized != 1) { > c = gmp_tests_dbl_mant_bits (); >

Re: mini-gmp mpz_{get,set}_d not fully compatible with GMP

2018-03-13 Thread Vincent Lefevre
On 2018-03-13 13:55:27 +0100, Torbjorn Granlund wrote: > Vincent Lefevre writes: > > On 2018-03-12 18:53:37 +0100, Marco Bodrato wrote: > > double > > mpz_get_d (const mpz_t u) > > { > > static int c = 0; > > static int __initialized = 0; > > > > if

Re: mini-gmp mpz_{get,set}_d not fully compatible with GMP

2018-03-13 Thread Vincent Lefevre
On 2018-03-13 15:12:27 +0100, Niels Möller wrote: > Does C11 provide any way to initialize a local static variable, like in > recent C++? I.e., not code running before main, but code running the > first time the function is entered, and guaranteed to run just once? I don't think so. 6.7.9p4 says

Re: mini-gmp mpz_{get,set}_d not fully compatible with GMP

2018-03-13 Thread Torbjörn Granlund
ni...@lysator.liu.se (Niels Möller) writes: Does C11 provide any way to initialize a local static variable, like in recent C++? I.e., not code running before main, but code running the first time the function is entered, and guaranteed to run just once? > I don't think volatile matters.

Re: mini-gmp mpz_{get,set}_d not fully compatible with GMP

2018-03-13 Thread Marc Glisse
On Tue, 13 Mar 2018, Niels Möller wrote: I'd still prefer the simpler way of reying on float.h constants, though +1 to that. For mini-gmp, maybe put all the functions using 'double' behind some macro or in a separate file so it is easy for a user to remove them, and document that they are

Re: mini-gmp mpz_{get,set}_d not fully compatible with GMP

2018-03-13 Thread Vincent Lefevre
On 2018-03-13 15:34:26 +0100, Torbjorn Granlund wrote: > ni...@lysator.liu.se (Niels Möller) writes: > If we can make this thread safe with C11, I think it's fine to document > that mini-gmp requires C11 for thread safety. (I'd still prefer the > simpler way of reying on float.h constants,

Re: mini-gmp mpz_{get,set}_d not fully compatible with GMP

2018-03-13 Thread Vincent Lefevre
On 2018-03-13 17:29:48 +0100, Marc Glisse wrote: > +1 to that. For mini-gmp, maybe put all the functions using 'double' behind > some macro or in a separate file so it is easy for a user to remove them, > and document that they are only supported with a standard float.h header. Or > just assume