Deprecated: The each() function is deprecated. This message will be suppressed on further calls in /home/zhenxiangba/zhenxiangba.com/public_html/phproxy-improved-master/index.php on line 456
Sylvie Boldo
[go: Go Back, main page]

Gallery of proved programs

Full proof using why3


Average of two floating-point numbers, correct version

This function computes the correct rounding of the average of two floating-point numbers. It gives the perfect value, while preventing overflows.


/*@ ensures \result == \abs(x); */
double abs(double x) {
  if (x >= 0) return x;
  else return (-x);
}


/*@   requires 0x1p-967 <= C <= 0x1p970; 
  @   ensures \result == \round_double(\NearestEven, (x+y)/2) ;
  @ */

double average(double C, double x, double y) {
  if (C <= abs(x)) 
    return x/2+y/2;
  else
    return (x+y)/2;
}

 
Inria

Interstices

Revue web de médiation scientifique
French popularization web journal