00001 // Authors: Matthew Saltzman and Ted Ralphs 00002 // Copyright 2015, Matthew Saltzman and Ted Ralphs 00003 // Licensed under the Eclipse Public License 1.0 00004 00005 #ifndef CoinRational_H 00006 #define CoinRational_H 00007 00008 #include <cmath> 00009 00010 //Small class for rational numbers 00011 class CoinRational 00012 { 00013 00014 public : 00015 long getDenominator() { return denominator_; } 00016 long getNumerator() { return numerator_; } 00017 00018 CoinRational(): 00019 numerator_(0), 00020 denominator_(1) 00021 {}; 00022 00023 CoinRational(long n, long d): 00024 numerator_(n), 00025 denominator_(d) 00026 {}; 00027 00028 CoinRational(double val, double maxdelta, long maxdnom) 00029 { 00030 if (!nearestRational_(val, maxdelta, maxdnom)){ 00031 numerator_ = 0; 00032 denominator_ = 1; 00033 } 00034 }; 00035 00036 private : 00037 00038 long numerator_; 00039 long denominator_; 00040 00041 bool nearestRational_(double val, double maxdelta, long maxdnom); 00042 }; 00043 00044 #endif