[SystemSafety] Accuracy of COVID modeling code

Derek M Jones derek at knosof.co.uk
Sat May 9 15:51:36 CEST 2020


Peter,

> Consider an example from Goldberg's survey which you reference, when a programmer writes "z := x^2 -
> y^2" , exactly what is it that "correctly uses the FPU" to ensure that z gets an appropriate and
> accurate value?
> 
> The answer is the programming system you are using. For example, does your compiler calculate x^2
> and y^2 and perform a subtraction, or does it calculate x+y and x-y and perform a multiplication? As
> Goldberg notes, there are differences. It is not the FPU which chooses how this calculation is to be
> performed, except in the limited cases handled in IEEE 754, but the HLL paraphernalia.

All the language specifications I am familiar with are very clear,
implement what the code says.  In your example, it's always do the multiples, and then
the subtracts.

What is a literal value close to pi appears in the source:
https://shape-of-code.coding-guidelines.com/2010/03/12/variations-in-the-literal-representation-of-pi/
should a compiler replace the value with a more accurate value of pi?

-- 
Derek M. Jones           Evidence-based software engineering
tel: +44 (0)1252 520667  blog:shape-of-code.coding-guidelines.com


More information about the systemsafety mailing list