패키지, 저장소 및 앱 카테고리 검색

패키지 상세v1.2.0

eval_ex

수학 및 부울 표현식 평가기로, https://github.com/uklimaschewski/EvalEx 에서 포트되었습니다.

AndroidiOSWebmacOSWindowsLinux
30일 다운로드
3.5천
좋아요
27
Pub 점수
145

패키지 설치

flutter pub add eval_ex

패키지 개요

공개 정보를 바탕으로 생성한 선택 가이드입니다.

EvalEx는 런타임에 수학식과 부울 표현식을 평가하는 가벼운 Dart 패키지입니다. 기본 산술 연산, 괄호, 변수 및 sin, cos, log와 같은 일반적인 함수를 지원합니다. 원래 자바스크립트 라이브러리에서 옮겨온 것으로, 안전하게 식을 파싱하고 계산하기 위한 간단한 API를 제공합니다. 계산기, 금융 도구, 또는 구성 기반 로직이 필요한 응용 프로그램에 적합합니다. 이 패키지는 모바일, 웹, 데스크톱을 포함한 모든 주요 플랫폼에서 작동합니다.

사용 사례

  • 동적 수식 계산
  • 계산기 앱
  • 구성 기반 로직
  • 재무 모델링
  • 데이터 검증
  • 과학 계산

주요 기능

  • 산술 및 부울 표현식을 지원합니다
  • 변수 치환
  • 내장 수학 함수
  • 안전한 표현 분석
  • 크로스 플랫폼 호환성
  • 간단한 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 개

소스 저장소

이 패키지를 사용하는 프로젝트

아직 데이터가 없습니다.