a14n / dart-rational

Apache License 2.0
35 stars 20 forks source link

Strange error in Rational multiplication #18

Closed vadimtsushko closed 6 years ago

vadimtsushko commented 6 years ago

It is probably some rare edge case - I use dart-rational for calculation in biggish dataset and got this first time: I can reproduce this with dart-rational 0.2.0 and Dart VM version: 2.0.0-dev.42.0 (Unknown timestamp) on "linux_x64"

import 'package:rational/rational.dart';

main() {

  var r1 = new Rational(new BigInt.from(4403993), new BigInt.from(1000));
  var r2 = new Rational(new BigInt.from(1384700050), new BigInt.from(9498883));
  var r3 = r1 * r2; /// this line is breaking
  print(r3);

}

This snippet breaks with error

Unhandled exception:
RangeError (index): Index out of range: index should be less than 2: 2
#0      Uint32List.[]= (dart:typed_data-patch/dart:typed_data/typed_data_patch.dart:2465)
#1      _BigIntImpl._divRem (dart:core-patch/dart:core/bigint_patch.dart:1382)
#2      _BigIntImpl._rem (dart:core-patch/dart:core/bigint_patch.dart:1306)
#3      _BigIntImpl.% (dart:core-patch/dart:core/bigint_patch.dart:1697)
#4      _gcd (package:rational/rational.dart:34:11)
#5      new Rational (package:rational/rational.dart:87:17)
#6      Rational.* (package:rational/rational.dart:146:46)
#7      main (file:///home/vts/project/infovizion/fifo/fifo_simple/bin/ad_hoq.dart:8:15)
#8      _startIsolate.<anonymous closure> (dart:isolate-patch/dart:isolate/isolate_patch.dart:279)
#9      _RawReceivePortImpl._handleMessage (dart:isolate-patch/dart:isolate/isolate_patch.dart:165)
a14n commented 6 years ago

Thanks for the report. Looks like a VM issue. I just created dart-lang/sdk#32739.

vadimtsushko commented 6 years ago

Thank you, I'll try to downgrade to 2.0.0-dev.28.0 meanwhile