math_compute 0.1.0 copy "math_compute: ^0.1.0" to clipboard
math_compute: ^0.1.0 copied to clipboard

A library to lex, parse and compute mathematical expressions.

example/math_compute_example.dart

import 'package:math_compute/base.dart';

void main() {
  // Example coming from https://en.wikipedia.org/wiki/Shunting_yard_algorithm#Detailed_examples
  final input = '5% + 100'; // 3 + 4 × 2 ÷ ( 1 − 5 ) ^ 2 ^ 3
  print('Computing "$input"...');
  final result = compute(input);

  if (!result.approximable()) {
    print('This is not approximable to a double!');
    return;
  }

  final approximation = result.approximate();
  print('The result is $result!');
  if (!approximation.isInteger) {
    if (approximation.hasFinitePrecision) {
      print('This is ${approximation.toDouble()}!');
    } else {
      print(
          'This is about ${approximation.toDouble()} but this isn\'t an exact value!');
    }
  }
}
1
likes
150
points
0
downloads

Publisher

unverified uploader

Weekly Downloads

A library to lex, parse and compute mathematical expressions.

Repository (GitHub)
View/report issues

Documentation

API reference

License

BSD-3-Clause (license)

Dependencies

logging, rational

More

Packages that depend on math_compute