diff --git a/Number_types/include/CGAL/cpp_float.h b/Number_types/include/CGAL/cpp_float.h index 422f76429bd..c5c73645366 100644 --- a/Number_types/include/CGAL/cpp_float.h +++ b/Number_types/include/CGAL/cpp_float.h @@ -353,21 +353,27 @@ public: std::pair to_interval() const { - assert(false); - double zero(0); - return std::make_pair(zero,zero); + if(exp == 0){ + return CGAL::to_interval(man); + } + if(exp > 0){ + Mantissa as = man << exp; + return CGAL::to_interval(as); + } + Mantissa pow(1); + pow <<= -exp; + boost::multiprecision::cpp_rational rat(man, pow); + return CGAL::to_interval(rat); } bool is_zero () const { - return man==0 && exp == 0; + return CGAL::is_zero(man); } bool is_one () const { - assert(false); - return true; - // return exp==0 && size==1 && data()[0]==1; + return *this == cpp_float(1); } @@ -394,8 +400,7 @@ public: struct Is_one : public CGAL::cpp98::unary_function< Type, bool > { bool operator()( const Type& x ) const { - assert(false); - return false; // x.is_one(); + return x.is_one(); } }; diff --git a/Number_types/test/Number_types/CMakeLists.txt b/Number_types/test/Number_types/CMakeLists.txt index 925f10a9efc..0b9acb0368d 100644 --- a/Number_types/test/Number_types/CMakeLists.txt +++ b/Number_types/test/Number_types/CMakeLists.txt @@ -13,6 +13,7 @@ include(CGAL_VersionUtils) include_directories(BEFORE include) create_single_source_cgal_program("bench_interval.cpp") +create_single_source_cgal_program("cpp_float.cpp") create_single_source_cgal_program("constant.cpp") create_single_source_cgal_program("CORE_BigFloat.cpp") create_single_source_cgal_program("CORE_BigInt.cpp") diff --git a/Number_types/test/Number_types/cpp_float.cpp b/Number_types/test/Number_types/cpp_float.cpp new file mode 100644 index 00000000000..55fb2155a49 --- /dev/null +++ b/Number_types/test/Number_types/cpp_float.cpp @@ -0,0 +1,53 @@ + +#include + +int main() +{ + + CGAL::cpp_float m(0); + std::cout << m << std::endl; + + CGAL::cpp_float m0(23.0); + + CGAL::cpp_float m1(5.0); + + CGAL::cpp_float m2(5.125); + + CGAL::cpp_float m3(2.5); + + CGAL::cpp_float m4(0.625); + + + CGAL::cpp_float m5(0.5); + + CGAL::is_positive(m5); + + assert(m4 > m5); + + assert(-m4 < -m5); + + + assert(-m4 == -m4); + + + assert(-m4 != -m5); + + assert(-m5 != -m4); + + CGAL::cpp_float m15 = m1 + m5; + m15 = m15 - m5; + assert(m15 == m1); + assert(! (m15 < m1)); + assert(! (m1 < m15)); + + m15 = m15 - m15; + std::cout << m15 << std::endl; + assert(m15.is_zero()); + + m1 *= m5; + + m0 += m4; + std::cout << m0 << std::endl; + + return 0; +}