Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

bad values for sin and cos methods for optimized code #12369

Closed
devoncarew opened this issue Aug 11, 2013 · 3 comments
Closed

bad values for sin and cos methods for optimized code #12369

devoncarew opened this issue Aug 11, 2013 · 3 comments
Labels
area-vm Use area-vm for VM related issues, including code coverage, and the AOT and JIT backends. P1 A high priority bug; for example, a single project is unusable or has many test failures

Comments

@devoncarew
Copy link
Member

This can be seen in the solar example, and in the following test case:

import 'dart:math' as math;

void main() {
  doMath(true);

  for (int i = 0; i < 1000000; i++) {
    if (!doMath()) {
      print("bad trig results at iteration $i");

      doMath(true);

      return;
    }
  }

  doMath(true);
}

bool doMath([bool doPrint = false]) {
  double angle = math.PI / 2;

  double sVal = math.sin(angle);
  double cVal = math.cos(angle);

  if (doPrint) {
    print("sin($angle) = $sVal, cos($angle) = $cVal");
  }

  return sVal != cVal;
}

I get the following results:

sin(1.5707963267948966) = 1.0, cos(1.5707963267948966) = 6.123031769111886e-17
bad trig results at iteration 2999
sin(1.5707963267948966) = 1.0, cos(1.5707963267948966) = 1.0

I.e. the results go bad after the 3000th iteration of calling the method.

@devoncarew
Copy link
Member Author

Possibly related to this CL: https://codereview.chromium.org//22266005 ?


cc @sgmitrovic.
cc @iposva-google.

@mraleph
Copy link
Member

mraleph commented Aug 11, 2013

UnaryMathInstr::AttributesEqual should compare kind_

right now all UnaryMathInstr instances are considered equal as long as they have the same arguments independently of what they actually compute (so here math.cos(angle) will be replaced with the result of math.sin(angle)).


Set owner to @sgmitrovic.

@ghost
Copy link

ghost commented Aug 12, 2013

Thanks for reporting this bug!

Fixed in r26014. Fix is has been identified by vegorov.


Added Fixed label.

@devoncarew devoncarew added Type-Defect P1 A high priority bug; for example, a single project is unusable or has many test failures area-vm Use area-vm for VM related issues, including code coverage, and the AOT and JIT backends. labels Aug 12, 2013
@devoncarew devoncarew assigned ghost Aug 12, 2013
This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-vm Use area-vm for VM related issues, including code coverage, and the AOT and JIT backends. P1 A high priority bug; for example, a single project is unusable or has many test failures
Projects
None yet
Development

No branches or pull requests

2 participants