int test_all_modes(bool synchronize) { // As stated above, we'd like this to be true for all // floating-point types: // X == 1.0e0 * X * 1.0e-0 // But this is not generally true for long doubles with x86 // compilers, which may use an 80-bit 'extended-real' format for // for long doubles, yet initialize the floating-point hardware // to use only a 53-bit mantissa--so initialize the hardware // explicitly. fenv_initialize(); e_ieee754_rounding hardware_rounding_mode = fe_tonearest; set_hardware_rounding_mode(hardware_rounding_mode, synchronize); std::cout << " hardware rounding mode: " << get_name_of_hardware_rounding_mode(hardware_rounding_mode) << std::endl ; test_rounding(); hardware_rounding_mode = fe_downward; set_hardware_rounding_mode(hardware_rounding_mode, synchronize); std::cout << " hardware rounding mode: " << get_name_of_hardware_rounding_mode(hardware_rounding_mode) << std::endl ; test_rounding(); hardware_rounding_mode = fe_upward; set_hardware_rounding_mode(hardware_rounding_mode, synchronize); std::cout << " hardware rounding mode: " << get_name_of_hardware_rounding_mode(hardware_rounding_mode) << std::endl ; test_rounding(); hardware_rounding_mode = fe_towardzero; set_hardware_rounding_mode(hardware_rounding_mode, synchronize); std::cout << " hardware rounding mode: " << get_name_of_hardware_rounding_mode(hardware_rounding_mode) << std::endl ; test_rounding(); return 0; }
/* IEC 559 and ISO C99 define a default startup environment */ static void initial_tests (void) { test_exceptions ("Initially all exceptions should be cleared", NO_EXC, 0); #ifdef FE_TONEAREST test_rounding ("Rounding direction should be initalized to nearest", FE_TONEAREST); #endif }
int main(void) { printf("** Floating-point single-precision constants ** \n"); printf("FLT_MIN = %E \n", FLT_MIN ); printf("FLT_MAX = %E \n", FLT_MAX ); printf("FLT_EPSILON = %E \n", FLT_EPSILON ); // En MATLAB: eps(single(1)) printf("\n"); printf("** Floating-point double-precision constants ** \n"); printf("DBL_MIN = %E \n", DBL_MIN ); printf("DBL_MAX = %E \n", DBL_MAX ); printf("DBL_EPSILON = %E \n", DBL_EPSILON ); // En MATLAB: eps(1) printf("\n"); printf("** Floating point rounding modes ** \n"); printf("Rounding Mode FE_TONEAREST = %d \n", FE_TONEAREST ); printf("Rounding Mode FE_DOWNWARD = %d \n", FE_DOWNWARD ); printf("Rounding Mode FE_UPWARD = %d \n", FE_UPWARD ); printf("Rounding Mode FE_TOWARDZERO = %d \n", FE_TOWARDZERO ); printf("\n"); current_rounding(); test_rounding(); printf("\n"); change_rounding(FE_DOWNWARD); current_rounding(); test_rounding(); printf("\n"); change_rounding(FE_UPWARD); current_rounding(); test_rounding(); printf("\n"); change_rounding(FE_TOWARDZERO); current_rounding(); test_rounding(); printf("\n"); return 0; }
int test_functions(void) { int retval = 0; retval |= test_settings(); retval |= test_rounding(); retval |= test_sticky(); retval |= test_precision(); retval |= test_class(); retval |= test_mask(); return retval; }