@@ -296,6 +296,12 @@ class MPFRNumber {
296
296
return result;
297
297
}
298
298
299
+ MPFRNumber div (const MPFRNumber &b) const {
300
+ MPFRNumber result (*this );
301
+ mpfr_div (result.value , value, b.value , mpfr_rounding);
302
+ return result;
303
+ }
304
+
299
305
MPFRNumber floor () const {
300
306
MPFRNumber result (*this );
301
307
mpfr_floor (result.value , value);
@@ -708,6 +714,8 @@ binary_operation_one_output(Operation op, InputType x, InputType y,
708
714
switch (op) {
709
715
case Operation::Atan2:
710
716
return inputX.atan2 (inputY);
717
+ case Operation::Div:
718
+ return inputX.div (inputY);
711
719
case Operation::Fmod:
712
720
return inputX.fmod (inputY);
713
721
case Operation::Hypot:
@@ -885,42 +893,47 @@ template void explain_binary_operation_two_outputs_error<long double>(
885
893
Operation, const BinaryInput<long double > &,
886
894
const BinaryOutput<long double > &, double , RoundingMode);
887
895
888
- template <typename T>
889
- void explain_binary_operation_one_output_error (Operation op,
890
- const BinaryInput<T> &input,
891
- T libc_result,
892
- double ulp_tolerance,
893
- RoundingMode rounding) {
894
- unsigned int precision = get_precision<T>(ulp_tolerance);
896
+ template <typename InputType, typename OutputType>
897
+ void explain_binary_operation_one_output_error (
898
+ Operation op, const BinaryInput<InputType> &input, OutputType libc_result,
899
+ double ulp_tolerance, RoundingMode rounding) {
900
+ unsigned int precision = get_precision<InputType>(ulp_tolerance);
895
901
MPFRNumber mpfrX (input.x , precision);
896
902
MPFRNumber mpfrY (input.y , precision);
897
- FPBits<T > xbits (input.x );
898
- FPBits<T > ybits (input.y );
903
+ FPBits<InputType > xbits (input.x );
904
+ FPBits<InputType > ybits (input.y );
899
905
MPFRNumber mpfr_result =
900
906
binary_operation_one_output (op, input.x , input.y , precision, rounding);
901
907
MPFRNumber mpfrMatchValue (libc_result);
902
908
903
909
tlog << " Input decimal: x: " << mpfrX.str () << " y: " << mpfrY.str () << ' \n ' ;
904
- tlog << " First input bits: " << str (FPBits<T >(input.x )) << ' \n ' ;
905
- tlog << " Second input bits: " << str (FPBits<T >(input.y )) << ' \n ' ;
910
+ tlog << " First input bits: " << str (FPBits<InputType >(input.x )) << ' \n ' ;
911
+ tlog << " Second input bits: " << str (FPBits<InputType >(input.y )) << ' \n ' ;
906
912
907
913
tlog << " Libc result: " << mpfrMatchValue.str () << ' \n '
908
914
<< " MPFR result: " << mpfr_result.str () << ' \n ' ;
909
- tlog << " Libc floating point result bits: " << str (FPBits<T>(libc_result))
910
- << ' \n ' ;
915
+ tlog << " Libc floating point result bits: "
916
+ << str (FPBits<OutputType>(libc_result)) << ' \n ' ;
911
917
tlog << " MPFR rounded bits: "
912
- << str (FPBits<T >(mpfr_result.as <T >())) << ' \n ' ;
918
+ << str (FPBits<OutputType >(mpfr_result.as <OutputType >())) << ' \n ' ;
913
919
tlog << " ULP error: " << mpfr_result.ulp_as_mpfr_number (libc_result).str ()
914
920
<< ' \n ' ;
915
921
}
916
922
917
- template void explain_binary_operation_one_output_error<float >(
918
- Operation, const BinaryInput<float > &, float , double , RoundingMode);
919
- template void explain_binary_operation_one_output_error<double >(
923
+ template void
924
+ explain_binary_operation_one_output_error (Operation, const BinaryInput<float > &,
925
+ float , double , RoundingMode);
926
+ template void explain_binary_operation_one_output_error (
920
927
Operation, const BinaryInput<double > &, double , double , RoundingMode);
921
- template void explain_binary_operation_one_output_error<long double >(
922
- Operation, const BinaryInput<long double > &, long double , double ,
923
- RoundingMode);
928
+ template void
929
+ explain_binary_operation_one_output_error (Operation,
930
+ const BinaryInput<long double > &,
931
+ long double , double , RoundingMode);
932
+ #ifdef LIBC_TYPES_HAS_FLOAT16
933
+ template void
934
+ explain_binary_operation_one_output_error (Operation, const BinaryInput<float > &,
935
+ float16, double , RoundingMode);
936
+ #endif
924
937
925
938
template <typename InputType, typename OutputType>
926
939
void explain_ternary_operation_one_output_error (
@@ -1051,26 +1064,35 @@ template bool compare_binary_operation_two_outputs<long double>(
1051
1064
Operation, const BinaryInput<long double > &,
1052
1065
const BinaryOutput<long double > &, double , RoundingMode);
1053
1066
1054
- template <typename T >
1067
+ template <typename InputType, typename OutputType >
1055
1068
bool compare_binary_operation_one_output (Operation op,
1056
- const BinaryInput<T> &input,
1057
- T libc_result, double ulp_tolerance,
1069
+ const BinaryInput<InputType> &input,
1070
+ OutputType libc_result,
1071
+ double ulp_tolerance,
1058
1072
RoundingMode rounding) {
1059
- unsigned int precision = get_precision<T >(ulp_tolerance);
1073
+ unsigned int precision = get_precision<InputType >(ulp_tolerance);
1060
1074
MPFRNumber mpfr_result =
1061
1075
binary_operation_one_output (op, input.x , input.y , precision, rounding);
1062
1076
double ulp = mpfr_result.ulp (libc_result);
1063
1077
1064
1078
return (ulp <= ulp_tolerance);
1065
1079
}
1066
1080
1067
- template bool compare_binary_operation_one_output<float >(
1068
- Operation, const BinaryInput<float > &, float , double , RoundingMode);
1069
- template bool compare_binary_operation_one_output<double >(
1070
- Operation, const BinaryInput<double > &, double , double , RoundingMode);
1071
- template bool compare_binary_operation_one_output<long double >(
1072
- Operation, const BinaryInput<long double > &, long double , double ,
1073
- RoundingMode);
1081
+ template bool compare_binary_operation_one_output (Operation,
1082
+ const BinaryInput<float > &,
1083
+ float , double , RoundingMode);
1084
+ template bool compare_binary_operation_one_output (Operation,
1085
+ const BinaryInput<double > &,
1086
+ double , double , RoundingMode);
1087
+ template bool
1088
+ compare_binary_operation_one_output (Operation, const BinaryInput<long double > &,
1089
+ long double , double , RoundingMode);
1090
+ #ifdef LIBC_TYPES_HAS_FLOAT16
1091
+ template bool compare_binary_operation_one_output (Operation,
1092
+ const BinaryInput<float > &,
1093
+ float16, double ,
1094
+ RoundingMode);
1095
+ #endif
1074
1096
1075
1097
template <typename InputType, typename OutputType>
1076
1098
bool compare_ternary_operation_one_output (Operation op,
0 commit comments