Uploaded image for project: 'Couchbase Server'
  1. Couchbase Server
  2. MB-30432

select tan(radians(45)) gives out 0.9999999999999999 instead of 1.

    XMLWordPrintable

Details

    • Untriaged
    • Unknown
    • CX Sprint 112, CX Sprint 113, CX Sprint 114

    Description

      select tan(radians(45)) gives out 0.9999999999999999 instead of 1.
      It works fine in N1QL.

      Attachments

        Issue Links

          No reviews matched the request. Check your Options in the drop-down menu of this sections header.

          Activity

            This is a property of the underlying platform (java in this case). A sensible way to test correctness across platforms could be to avoid testing the full value and instead refund the result to a desired number of digits.

            till Till Westmann added a comment - This is a property of the underlying platform (java in this case). A sensible way to test correctness across platforms could be to avoid testing the full value and instead refund the result to a desired number of digits.
            till Till Westmann added a comment - - edited

            Ritesh Agarwal it doesn't seem to make sense to try to fix the behavior of the underlying platform. If you run this example

            public class Test {
                public static void main(String[] args) {
                    double digits = 8;
                    double mutiplier = Math.pow(10d, digits);
                    double tan = Math.tan(Math.toRadians(45.0));
                    System.out.println(tan);
                    System.out.println(Math.round(tan*digits)/digits);
                }
            }
            

            you'll see, that

            1. the Java platform's arithmetics produce exactly this result and that
            2. rounding to a useful number of digits will yield the "1.0" string.

            Like an application that requires a specific precision, the test framework should enforce the precision for these test cases.

            till Till Westmann added a comment - - edited Ritesh Agarwal it doesn't seem to make sense to try to fix the behavior of the underlying platform. If you run this example public class Test { public static void main(String[] args) { double digits = 8 ; double mutiplier = Math.pow(10d, digits); double tan = Math.tan(Math.toRadians( 45.0 )); System.out.println(tan); System.out.println(Math.round(tan*digits)/digits); } } you'll see, that the Java platform's arithmetics produce exactly this result and that rounding to a useful number of digits will yield the "1.0" string. Like an application that requires a specific precision, the test framework should enforce the precision for these test cases.

            Handled this in the test assert. Note that the behavior is different in this case between N1QL and SQL++ because of the underlying platform.

            ritesh.agarwal Ritesh Agarwal added a comment - Handled this in the test assert. Note that the behavior is different in this case between N1QL and SQL++ because of the underlying platform.

            Same is the case with:

            • select degrees(asin(0.5))
            ritesh.agarwal Ritesh Agarwal added a comment - Same is the case with: select degrees(asin(0.5))

            People

              ritesh.agarwal Ritesh Agarwal
              ritesh.agarwal Ritesh Agarwal
              Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved:

                Gerrit Reviews

                  There are no open Gerrit changes

                  PagerDuty