Skip to content

Instantly share code, notes, and snippets.

@alexshires
Created January 29, 2014 17:06
Show Gist options
  • Save alexshires/8692338 to your computer and use it in GitHub Desktop.
Save alexshires/8692338 to your computer and use it in GitHub Desktop.
class value {
public:
value::value() { central = 1.0 ; error = 0.0 ; }
value::value(double a, double b) { central = a ; error = b ; }
double val() { return central ; }
double err() { return error ; }
value operator* (value v) {
double error = (this->error * this->error * v.val() * v.val()) ;
error += (v.err() * v.err() * this->value * this->value ) ;
return value( this->central * v.val() , sqrt(error)) ;
}
value operator/ (value v) {
if (v.val() <= 0 ) return value(0.0,0.0) ;
double error1 = (this->error * this->error / v.val() / v.val()) ;
double error2 += (v.err() * v.err() * this->value * this->value ) ;
error2 /= (v.val() * v.val() * v.val() * v.val() ) ;
return value( this->central / v.val() , sqrt(error1+error2)) ;
}
private:
double central ;
double error ;
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment