Tuesday, 15 January 2013

numerical - Is C floating-point non-deterministic? -



numerical - Is C floating-point non-deterministic? -

i have read somewhere there source of non-determinism in c double-precision floating point follows:

the c standard says 64-bit floats (doubles) required produce 64-bit accuracy.

hardware may floating point in 80-bit registers.

because of (1), c compiler not required clear low-order bits of floating-point registers before stuffing double high-order bits.

this means ymmv, i.e. little differences in results can happen.

is there now-common combination of hardware , software happens? see in other threads .net has problem, c doubles via gcc ok? (e.g. testing convergence of successive approximations based on exact equality)

the behavior on implementations excess precision, seems issue you're concerned about, specified strictly standard in if not cases. combined ieee 754 (assuming c implementation follows annex f) not leave room kinds of non-determinism seem asking about. in particular, things x == x (which mehrdad mentioned in comment) failing forbidden since there rules when excess precision kept in look , when discarded. explicit casts , assignment object among operations drop excess precision , ensure you're working nominal type.

note there still lot of broken compilers out there don't conform standards. gcc intentionally disregards them unless utilize -std=c99 or -std=c11 (i.e. "gnu99" , "gnu11" options intentionally broken in regard). , prior gcc 4.5, right handling of excess precision not supported.

c numerical

No comments:

Post a Comment