パッケージ、リポジトリ、アプリカテゴリを検索

パッケージ詳細v1.2.0

eval_ex

数学および論理式の評価器で、https://github.com/uklimaschewski/EvalEx から移植されました。

AndroidiOSWebmacOSWindowsLinux
30日間ダウンロード
3460
いいね数
27
Pub ポイント
145

パッケージをインストール

flutter pub add eval_ex

パッケージ概要

公開情報に基づく選定ガイドです。参考としてご利用ください。

EvalEx は、実行時に数式およびブール式を評価する軽量なDartパッケージです。基本的な算術演算、括弧、変数、および sin、cos、log などの一般的な関数をサポートしています。もともとJavaScriptライブラリから移植されたもので、式の解析と計算を安全に行うためのシンプルなAPIを提供します。電卓、財務ツール、または構成ベースの論理処理を必要とするアプリケーションに最適です。このパッケージは、モバイル、Web、デスクトップなどすべての主要プラットフォームで動作します。

用途

  • 動的数式計算
  • 電卓アプリ
  • 設定ベースの論理
  • ファイナンスモデリング
  • データ検証
  • 科学計算

主な機能

  • 算術および論理式をサポートしています
  • 変数置換
  • 組み込みの数学関数
  • 安全な式の解析
  • クロスプラットフォーム互換性
  • 最小限のセットアップで簡単なAPI

適している対象

  • 電卓を開発する開発者
  • 実行時式の評価を必要とするアプリケーション
  • 教育ツール
  • ユーザー定義の数式を用いたバックエンドロジック
  • 動的計算のプロトタイピング

注意事項

  • 非常に複雑またはパフォーマンスが重要な数学には適していません
  • カスタム関数定義のサポートなし
  • 式は構文的に有効でなければならない
  • 基本操作および標準関数に限定
  • 信頼できない入力に対するセキュリティの注意喚起

元の README

関連するソースリポジトリの README 原文のスナップショットです。最新の内容はリポジトリをご覧ください。

eval_ex

A Dart port of https://github.com/uklimaschewski/EvalEx.
EvalEx supports mathematical and boolean expression evaluation, using arbitrary precision. EvalEx supports functions, variables, and operators and additionally makes it very easy to add your own custom functions or operators.

EvalEx uses decimal to support arbitrary precision arithmetic.
View package on pub.dev.

Basic example

void main() {
  Expression exp = Expression("2 ^ 4 + 8");
  print(exp.eval().toString()); // 24

  // With a variable
  exp = Expression("a ^ b + c");
  // Variables may contain alphanumeric characters, and "_". This can be changed
  // by using setVariableCharacters(..) and setFirstVariableCharacters(..) (what chars variable are allowed to start with).
  exp.setStringVariable("a", "2");
  exp.setStringVariable("b", "4");
  exp.setStringVariable("c", "8");
  print(exp.eval().toString()); // 24
  
  // With a function
  exp = Expression("MAX(-7,8)");
  print(exp.eval().toString()); // 8

  // Boolean logic
  exp = Expression("1>0 && 5 == 5");
  print(exp.eval().toString()); // 1
  
  exp = Expression("1>0 && 5 == 4");
  print(exp.eval().toString()); // 0
}
 

Built-in functions and operators

Function Description
+ Addition
- Subtraction
* Multiplication
/ Division
% Modulus
^ Power
&& Returns 1 if both expressions are true, 0 otherwise
|| Returns 1 if either or both expressions are true, 0 otherwise
> Returns 1 if the left expression is greater than the right
>= Returns 1 if the left expression is greater than or equal to the right
< Returns 1 if the right expression is greater than the left
<= Returns 1 if the right expression is greater than or equal to the left
= Returns 1 if the left and right expressions are equal
== Returns 1 if the left and right expressions are equal
!= Returns 1 if the left and right expressions are NOT equal
<> Returns 1 if the left and right expressions are NOT equal
STREQ("str1","str2") Returns 1 if the literal "str1" is equal to "str2", otherwise returns 0
FACT(int) Computes the factorial of arg1
NOT(expression) Returns 1 if arg1 evaluates to 0, otherwise returns 0
IF(cond,exp1,exp2) Returns exp1 if cond evaluates to 1, otherwise returns exp2
Random() Returns a random decimal between 0 and 1
SINR(exp) Evaluates the SIN of exp, assuming exp is in radians
COSR(exp) Evaluates the COS of exp, assuming exp is in radians
TANR(exp) Evaluates the TAN of exp, assuming exp is in radians
COTR(exp) Evaluates the COT of exp, assuming exp is in radians
SECR(exp) Evaluates the SEC of exp, assuming exp is in radians
CSCR(exp) Evaluates the CSC of exp, assuming exp is in radians
SIN(exp) Evaluates the SIN of exp, assuming exp is in degrees
COS(exp) Evaluates the COS of exp, assuming exp is in degrees
TAN(exp) Evaluates the TAN of exp, assuming exp is in degrees
COT(exp) Evaluates the COT of exp, assuming exp is in degrees
SEC(exp) Evaluates the SEC of exp, assuming exp is in degrees
CSC(exp) Evaluates the CSC of exp, assuming exp is in degrees
ASINR(exp) Evaluates the ARCSIN of exp, assuming exp is in radians
ACOSR(exp) Evaluates the ARCCOS of exp, assuming exp is in radians
ATANR(exp) Evaluates the ARCTAN of exp, assuming exp is in radians
ACOTR(exp) Evaluates the ARCCOT of exp, assuming exp is in radians
ATAN2R(exp1, exp1) Evaluates the ARCTAN between exp1 and exp2, assuming exp1 and exp2 are in radians
ASIN(exp) Evaluates the ARCSIN of exp, assuming exp is in degrees
ACOS(exp) Evaluates the ARCCOS of exp, assuming exp is in degrees
ATAN(exp) Evaluates the ARCTAN of exp, assuming exp is in degrees
ACOT(exp) Evaluates the ARCCOT of exp, assuming exp is in degrees
ATAN2(exp1, exp1) Evaluates the ARCTAN between exp1 and exp2, assuming exp1 and exp2 are in degrees
RAD(deg) Converts deg to radians
DEG(rad) Converts rad to degrees
MAX(a,b,...) Returns the maximum value from the provided list of 1 or more expressions
MIN(a,b,...) Returns the minimum value from the provided list of 1 or more expressions
ABS(exp) Returns the absolute value of exp
LOG(exp) Returns the natural logarithm of exp
LOG10(exp) Returns the log base 10 of exp
ROUND(exp,precision) Returns exp rounded to precision decimal points
FLOOR(exp) Returns the floor of exp
CEILING(exp) Returns the ceiling of exp
SQRT(exp) Computes the square root of exp
e Euler's number
PI Ratio of circle's circumference to diameter
NULL Alias for null
TRUE or true Alias for 1
FALSE or false Alias for 0

Adding custom functions, operators, and variables

Custom functions, operators, and variables can be defined by adding them in built_ins.dart

Differences from https://github.com/uklimaschewski/EvalEx.

  • Hyperbolic functions aren't supported
  • The SQRT function is currently limited to 64-bit precision
  • Built in operators/functions/variables are instead defined in built_ins.dart

カテゴリー

依存関係

依存関係一覧 2 件

ソースリポジトリ

このパッケージを使用しているプロジェクト

データはまだありません。