fkleon / math-expressions

A library for parsing and evaluating mathematical expressions, supporting real numbers, vectors, and basic interval arithmetic.
https://pub.dev/packages/math_expressions
MIT License
102 stars 36 forks source link

Any values that have greater power library crash the app and app is stuck on that state #57

Closed alihassan143 closed 2 years ago

fkleon commented 2 years ago

Hi @alihassan143 thanks for creating this issue. I can't reproduce this without more details, could you please provide an example that triggers the issue?

alihassan143 commented 2 years ago

98^789

alihassan143 commented 2 years ago

or 78^7897^7867. if i add more power the library stops the app for performing other tasks and crash the app

fkleon commented 2 years ago

I'm still not able to reproduce this. I've created a simple benchmark here comparing Dart's pow function and math_expressions: 75d793f9aebbc9a4c5f4fe6fc8f42e4fecda0825

On my machine this evaluates quickly and correctly to Infinity in both cases, math_expressions being about 66% slower than Dart's native pow function.

The benchmark below is for 10,000 iterations each as per commit:

$ dart run benchmark
 DONE  ./benchmark/power_benchmark.dart (5 s)
 ✓ Math.pow (3 ms)
 ✓ math_expressions.pow (5 ms)

Benchmark suites: 1 passed, 1 total
Benchmarks:       2 passed, 2 total
Time:             5 s

What hardware and architecture are you experiencing this issue on? Does it also happen when you use math.pow?

alihassan143 commented 2 years ago

this is happening when i used your library in app and i call parser.parse() in init state the library stuck the app in one state i even try the future delayed but this still this stop the app from working

alihassan143 commented 2 years ago

i am using intel base macbook pro and i try this values on both real device and emulator app still crash even i try the debugging the app but debugger did not show error also

fkleon commented 2 years ago

Thanks for the additional details. I've looked at the parser and added a similar benchmark, and am still not able to reproduce this.

Are you sure that the call to parse() is causing the delay, and not some code in your application? Could you share a minimal code snippet that can be used to reproduce this?

For further investigation it would also be helpful to:

alihassan143 commented 2 years ago

yes its caused by the parser because i also limit length of the string but when parsing the greater values it stuck the app

fkleon commented 2 years ago

@alihassan143 Any chance you can provide any of the additional details I asked for in https://github.com/fkleon/math-expressions/issues/57#issuecomment-995131351?

The example expressions you've given earlier do not reproduce the issue for me and are parsing in a few milliseconds at most. I've tried with 98^789, 78^7897^7867 and 78^78*97^78*67.

alihassan143 commented 2 years ago

now i find the cause is that flutter text widget shows error on long string i am converting the powers into real number that is generating long string and flutter text widget is not able to handle that string