Skip to content

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

Closed
@devoncarew

Description

@devoncarew

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    P1A high priority bug; for example, a single project is unusable or has many test failuresarea-vmUse area-vm for VM related issues, including code coverage, and the AOT and JIT backends.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions