This package includes several "constable math functions" that can be called at compile-time which dart:math mostly cannot, returning const double, and can be used as compile-time constants.
They are const constructors of extension type on double implements double, therefore can be used just like normal double, with almost 0 cost.
The package is seperated into 2 libraries, for older package:const_math/constmath.dart retain extension type syntax, while newer package:const_math/functions.dart ignored the camel_case_types lint rule to provide function-like syntax.
This package is and will not be optimized for run-time, for run time calculation, condider using 'dart:math' or other libraries.
Features
Constants
- ConstMath.pi()
- ConstMath.e()
Basic functions
- ConstMath.abs(num d)
- ConstMath.sgn(num d)
- ConstMath.min(num a, num b, [num c, num d, num e, num f, num g, num h, num i, num j])
- ConstMath.max(num a, num b, [num c, num d, num e, num f, num g, num h, num i, num j])
- ConstMath.degToRad(num d)
- ConstMath.radToDeg(num d)
Trigonometric functions
- ConstMath.sin(num d)
- ConstMath.cos(num d)
- ConstMath.tan(num d)
- ConstMath.cot(num d)
- ConstMath.sec(num d)
- ConstMath.csc(num d)
Log functions
- ConstMath.log(num d)
- ConstMath.log2(num d)
- ConstMath.log10(num d)
Exponent functions
- ConstMath.exp(num d)
- ConstMath.pow(num a, num b)
Inverse trigonometric functions
- ConstMath.asin(num d)
- ConstMath.acos(num d)
- ConstMath.atan(num d)
- ConstMath.atan2(num y, num x)
Root functions
- ConstMath.sqrt(num d)
- ConstMath.cbrt(num d)
- ConstMath.rt5(num d)
- ConstMath.rt7(num d)
Hyperbolic trigonometric funcions
- ConstMath.sinh(num d)
- ConstMath.cosh(num d)
- ConstMath.tanh(num d)
- ConstMath.coth(num d)
- ConstMath.sech(num d)
- ConstMath.coth(num d)
Error functions
- ConstMath.erf(num d)
- ConstMath.erfc(num d)
Getting started
In pubspec.yaml, add
dependencies:
const_math: ^1.1.0
and run the pub get. In the place you wish to use these functions,
import 'package:const_math/const_math.dart';
Alternatively, if you prefer function-like syntax, you can add this:
import 'package:const_math/functions.dart';
This might conflict to dart:math library, add prefix if needed.
Usage
These are compile time math functions that dart math does not provide, implemented by extension type on double.
const mySinValue = ConstMath.sin(3);
Alternatively for using package:const_math/functions.dart library, you can use syntax like this:
const mySinValue = sin(3);
Additional information
If need support or to report bugs, email: const_math_support@worldoverwrite.com
Libraries
- const_math
- This is a package for anyone who wish to have compile-time math functions. Not optimized for run-time, for any run-time usage, use 'dart:math' instead.
- functions
- This is a package for anyone who wish to have compile-time math functions and believe these functions should look like functions instead of extension type. Not optimized for run-time, for any run-time usage, use 'dart:math' instead.