Created
January 29, 2014 17:06
-
-
Save alexshires/8692338 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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