DriveHQ Start Menu
Cloud Drive Mapping
Folder Sync
Cloud Backup
True Drop Box
FTP/SFTP Hosting
Group Account
DriveHQ Start Menu
Online File Server
My Storage
|
Manage Shares
|
Publishes
|
Drop Boxes
|
Group Account
WebDAV Drive Mapping
Cloud Drive Home
|
WebDAV Guide
|
Drive Mapping Tool
|
Drive Mapping URL
Complete Data Backup
Backup Guide
|
Online Backup Tool
|
Cloud-to-Cloud Backup
FTP, Email & Web Service
FTP Home
|
FTP Hosting FAQ
|
Email Hosting
|
EmailManager
|
Web Hosting
Help & Resources
About
|
Enterprise Service
|
Partnership
|
Comparisons
|
Support
Quick Links
Security and Privacy
Download Software
Service Manual
Use Cases
Group Account
Online Help
Blog
Contact
Cloud Surveillance
Sign Up
Login
Features
Business Features
Online File Server
FTP Hosting
Cloud Drive Mapping
Cloud File Backup
Email Backup & Hosting
Cloud File Sharing
Folder Synchronization
Group Management
True Drop Box
Full-text Search
AD Integration/SSO
Mobile Access
IP Camera & DVR Solution
More...
Personal Features
Personal Cloud Drive
Backup All Devices
Mobile APPs
Personal Web Hosting
Sub-Account (for Kids)
Home/PC/Kids Monitoring
More...
Software
DriveHQ Drive Mapping Tool
DriveHQ FileManager
DriveHQ Online Backup
DriveHQ Mobile Apps
Pricing
Business Plans & Pricing
Personal Plans & Pricing
Price Comparison with Others
Feature Comparison with Others
Install Mobile App
Sign up
Creating account...
Invalid character in username! Only 0-9, a-z, A-Z, _, -, . allowed.
Username is required!
Invalid email address!
E-mail is required!
Password is required!
Password is invalid!
Password and confirmation do not match.
Confirm password is required!
I accept
Membership Agreement
Please read the Membership Agreement and check "I accept"!
Free Quick Sign-up
Sign-up Page
Log in
Signing in...
Username or e-mail address is required!
Password is required!
Keep me logged in
Quick Login
Forgot Password
Up
Upload
Download
Share
Publish
New Folder
New File
Copy
Cut
Delete
Paste
Rate
Upgrade
Rotate
Effect
Edit
Slide
History
// (C) Copyright Gennadiy Rozental 2001-2007. // Distributed under the Boost Software License, Version 1.0. // (See accompanying file LICENSE_1_0.txt or copy at // http://www.boost.org/LICENSE_1_0.txt) // See http://www.boost.org/libs/test for the library home page. // // File : $RCSfile$ // // Version : $Revision: 41369 $ // // Description : defines algoirthms for comparing 2 floating point values // *************************************************************************** #ifndef BOOST_TEST_FLOATING_POINT_COMPARISON_HPP_071894GER #define BOOST_TEST_FLOATING_POINT_COMPARISON_HPP_071894GER #include
// for std::numeric_limits #include
#include
//____________________________________________________________________________// namespace boost { namespace test_tools { using unit_test::readonly_property; // ************************************************************************** // // ************** floating_point_comparison_type ************** // // ************************************************************************** // enum floating_point_comparison_type { FPC_STRONG, // "Very close" - equation 1' in docs, the default FPC_WEAK // "Close enough" - equation 2' in docs. }; // ************************************************************************** // // ************** details ************** // // ************************************************************************** // namespace tt_detail { // FPT is Floating-Point Type: float, double, long double or User-Defined. template
inline FPT fpt_abs( FPT arg ) { return arg < static_cast
(0) ? -arg : arg; } //____________________________________________________________________________// template
struct fpt_limits { static FPT min_value() { return std::numeric_limits
::is_specialized ? (std::numeric_limits
::min)() : 0; } static FPT max_value() { return std::numeric_limits
::is_specialized ? (std::numeric_limits
::max)() : static_cast
(1000000); // for the our purpuses it doesn't really matter what value is returned here } }; //____________________________________________________________________________// // both f1 and f2 are unsigned here template
inline FPT safe_fpt_division( FPT f1, FPT f2 ) { // Avoid overflow. if( f2 < static_cast
(1) && f1 > f2*fpt_limits
::max_value() ) return fpt_limits
::max_value(); // Avoid underflow. if( f1 == static_cast
(0) || f2 > static_cast
(1) && f1 < f2*fpt_limits
::min_value() ) return static_cast
(0); return f1/f2; } //____________________________________________________________________________// } // namespace tt_detail // ************************************************************************** // // ************** tolerance presentation types ************** // // ************************************************************************** // template
struct percent_tolerance_t { explicit percent_tolerance_t( FPT v ) : m_value( v ) {} FPT m_value; }; //____________________________________________________________________________// template
Out& operator<<( Out& out, percent_tolerance_t
t ) { return out << t.m_value; } //____________________________________________________________________________// template
inline percent_tolerance_t
percent_tolerance( FPT v ) { return percent_tolerance_t
( v ); } //____________________________________________________________________________// template
struct fraction_tolerance_t { explicit fraction_tolerance_t( FPT v ) : m_value( v ) {} FPT m_value; }; //____________________________________________________________________________// template
Out& operator<<( Out& out, fraction_tolerance_t
t ) { return out << t.m_value; } //____________________________________________________________________________// template
inline fraction_tolerance_t
fraction_tolerance( FPT v ) { return fraction_tolerance_t
( v ); } //____________________________________________________________________________// // ************************************************************************** // // ************** close_at_tolerance ************** // // ************************************************************************** // template
class close_at_tolerance { public: // Public typedefs typedef bool result_type; // Constructor template
explicit close_at_tolerance( percent_tolerance_t
tolerance, floating_point_comparison_type fpc_type = FPC_STRONG ) : p_fraction_tolerance( tt_detail::fpt_abs( static_cast
(0.01)*tolerance.m_value ) ) , p_strong_or_weak( fpc_type == FPC_STRONG ) {} template
explicit close_at_tolerance( fraction_tolerance_t
tolerance, floating_point_comparison_type fpc_type = FPC_STRONG ) : p_fraction_tolerance( tt_detail::fpt_abs( tolerance.m_value ) ) , p_strong_or_weak( fpc_type == FPC_STRONG ) {} bool operator()( FPT left, FPT right ) const { FPT diff = tt_detail::fpt_abs( left - right ); FPT d1 = tt_detail::safe_fpt_division( diff, tt_detail::fpt_abs( right ) ); FPT d2 = tt_detail::safe_fpt_division( diff, tt_detail::fpt_abs( left ) ); return p_strong_or_weak ? (d1 <= p_fraction_tolerance && d2 <= p_fraction_tolerance) : (d1 <= p_fraction_tolerance || d2 <= p_fraction_tolerance); } // Public properties readonly_property
p_fraction_tolerance; readonly_property
p_strong_or_weak; }; //____________________________________________________________________________// // ************************************************************************** // // ************** check_is_close ************** // // ************************************************************************** // struct BOOST_TEST_DECL check_is_close_t { // Public typedefs typedef bool result_type; template
bool operator()( FPT left, FPT right, percent_tolerance_t
tolerance, floating_point_comparison_type fpc_type = FPC_STRONG ) { close_at_tolerance
pred( tolerance, fpc_type ); return pred( left, right ); } template
bool operator()( FPT left, FPT right, fraction_tolerance_t
tolerance, floating_point_comparison_type fpc_type = FPC_STRONG ) { close_at_tolerance
pred( tolerance, fpc_type ); return pred( left, right ); } }; namespace { check_is_close_t check_is_close; } //____________________________________________________________________________// // ************************************************************************** // // ************** check_is_small ************** // // ************************************************************************** // struct BOOST_TEST_DECL check_is_small_t { // Public typedefs typedef bool result_type; template
bool operator()( FPT fpv, FPT tolerance ) { return tt_detail::fpt_abs( fpv ) < tt_detail::fpt_abs( tolerance ); } }; namespace { check_is_small_t check_is_small; } //____________________________________________________________________________// } // namespace test_tools } // namespace boost //____________________________________________________________________________// #include
#endif // BOOST_FLOATING_POINT_COMAPARISON_HPP_071894GER
floating_point_comparison.hpp
Page URL
File URL
Prev
6/28
Next
Download
( 8 KB )
Note: The DriveHQ service banners will NOT be displayed if the file owner is a paid member.
Comments
Total ratings:
0
Average rating:
Not Rated
Would you like to comment?
Join DriveHQ
for a free account, or
Logon
if you are already a member.