All Projects → 5anthosh → fcal

5anthosh / fcal

Licence: MIT license
Extensive math expression evaluator library for JavaScript and Node.js

Programming Languages

typescript
32286 projects

Projects that are alternatives of or similar to fcal

Calculatex
in progress pretty printing calculator language
Stars: ✭ 302 (+251.16%)
Mutual labels:  calculator, interpreter, math
Notecalc3
NoteCalc is a handy calculator trying to bring the advantages of Soulver to the web.
Stars: ✭ 879 (+922.09%)
Mutual labels:  calculator, math
Php Math Parser
Simple mathematical expression parser and calculator.
Stars: ✭ 24 (-72.09%)
Mutual labels:  calculator, math
Kairos
A non date-based time calculator
Stars: ✭ 100 (+16.28%)
Mutual labels:  calculator, math
keisan
A Ruby-based expression parser, evaluator, and programming language
Stars: ✭ 48 (-44.19%)
Mutual labels:  calculator, math
Algebraicengine Fraction
a calculating engine~
Stars: ✭ 311 (+261.63%)
Mutual labels:  calculator, math
String Calc
PHP calculator library for mathematical terms (expressions) passed as strings
Stars: ✭ 60 (-30.23%)
Mutual labels:  calculator, math
node calculator
Create Maya node-network by entering a math-formula.
Stars: ✭ 56 (-34.88%)
Mutual labels:  calculator, math
Kalk
A calculator/expression evaluator written in rust that supports variables and functions.
Stars: ✭ 134 (+55.81%)
Mutual labels:  calculator, math
Computator.net
Computator.NET is a special kind of numerical software that is fast and easy to use but not worse than others feature-wise. It's features include: - Real and complex functions charts - Real and complex calculator - Real functions numerical calculations including different methods - Over 107 Elementary functions - Over 141 Special functions - Over 21 Matrix functions and operations - Scripting language with power to easy computations including matrices - You can declare your own custom functions with scripting language
Stars: ✭ 174 (+102.33%)
Mutual labels:  calculator, math
cpc
Text calculator with support for units and conversion
Stars: ✭ 89 (+3.49%)
Mutual labels:  calculator, math
desktop
Extendable calculator for the 21st Century ⚡
Stars: ✭ 85 (-1.16%)
Mutual labels:  calculator, math
Atosym
algebraic expressions parsing and evaluation through a property system based algorithm
Stars: ✭ 15 (-82.56%)
Mutual labels:  calculator, math
Nasc
Do maths like a normal person
Stars: ✭ 396 (+360.47%)
Mutual labels:  calculator, math
quich
Just an advanced terminal calculator.
Stars: ✭ 59 (-31.4%)
Mutual labels:  calculator, math
Sharpmath
A small .NET math library.
Stars: ✭ 36 (-58.14%)
Mutual labels:  calculator, math
string-math
Evaluates a math expression from a string. Supports variables and custom operators.
Stars: ✭ 14 (-83.72%)
Mutual labels:  calculator, math
rclc
Mathematical expression calculator with big integers, floats, common fractions, and complex numbers support
Stars: ✭ 24 (-72.09%)
Mutual labels:  calculator, math
Calc
C-style arbitrary precision calculator
Stars: ✭ 127 (+47.67%)
Mutual labels:  calculator, math
kalker
Kalker/kalk is a calculator with math syntax that supports user-defined variables and functions, complex numbers, and estimation of derivatives and integrals
Stars: ✭ 1,237 (+1338.37%)
Mutual labels:  calculator, math

iamg

FOSSA Status Version License: MIT Hits Downloads

🏠 Homepage

Fcaljs is an extensive math expression evaluator library for JavaScript and Node.js. Using fcal, you can perform basic arithmetic, percentage operations with precision. It features a flexible expression parser with a large set of built-in units, functions and constants. Inspired from Soulver

Fcal gui

Features

  • Units
  • Variables
  • Functions

Playground Fcal GUI, Codepen , CLI

Example

const fcal = new Fcal();
// New variable
fcal.evaluate('radius : 23 m'); // 23 Meters

fcal.evaluate('PI * radius ^ 2'); // 1661.9025137490006231 Meters

fcal.evaluate('PI2 * radius'); // 144.51326206514 Meters

// Predefined functions
fcal.evaluate('log(23)'); // 1.3617278360175928789

// Percentage
fcal.evaluate('23 % of 1023'); // 235.29

fcal.evaluate('200 sec + 120 %'); // 440 Seconds

// Unit conversion
fcal.evaluate('20 minutes + 34 day in sec'); // 2938800 Seconds

fcal.evaluate('sin(PI)'); // -1.6167204971158028306e-24

// Constants
fcal.evaluate('E'); // 2.718281828459045235360287

// Predefined units
fcal.evaluate('speed = 20 kph'); // 20 km/h

fcal.evaluate('speed in mps'); // 5.5555555555555555556 m/s

fcal.evaluate('23 C add 123 F'); // 196.40000000000004 °F

fcal.evaluate('1.2 nsec + 3 week in sec'); // 1814400.0000000012 Seconds

// Various number system
fcal.evaluate('0b1010011 day + 45'); // 128 Days

fcal.evaluate('23.44 kmh in oct'); //  0o27.341217270243656051 km/h

Install

Browser

the library is the single JavaScript file fcal.js (or minified, fcal.min.js).

<script src="https://cdn.jsdelivr.net/npm/fcal/dist/fcal.js"></script>

With NPM

$ npm install --save fcal
const { Fcal } = require('fcal');

Use

const { Fcal } = require('fcal');

const fcal = new Fcal();
var value = fcal.evaluate('102 day in minutes + abs(-34 day) in sec');

console.log(value); // 11750400 Seconds

Percentage

var value = fcal.evaluate('27% of 230 cm');
console.log(value); // 62.1 Centimeters

You can perform general percentage operation with + , -

var value = fcal.evaluate('1024 m + 6.1%');
console.log(value); // 1086.464 Meters

If type of left and right hand side of of is same, then operation will return percentage

var value = fcal.evaluate('10 of 10.100');
console.log(value); // % 99.009900990099009901

Scales

You can use Thousand k, million M and billion B scales.

var value = Fcal.eval('-0x14 M');
console.log(value); //-20000000

Equality and comparison

console.log(Fcal.eval('100 == 1230')); // false
console.log(Fcal.eval('20 cm < 1 m')); // true
console.log(Fcal.eval('100 cm != 100 m')); // true

You can use === to compare irrespective type of value

console.log(Fcal.eval('100 C === 100 F')); // true

Ternary operator

var value = Fcal.eval('234 cm > 1 m and true ? 34: 100');
console.log(value); // 34

Syntax errors

Fcal will throw exception if there is error with expression

For more error context, use info method in FcalError

try {
  var value = Fcal.eval('343 + 23.45E+*34');
} catch (e) {
  if (e instanceof FcalError) {
    console.log(e.info());
  }
}

/*
err: Expecting number after + but got '*'
| 343 + 23.45E+*34
| ......^^^^^^^
*/

Format

Format the results

var value = Fcal.eval('10345345.3454');
console.log(value.toFormat()); // 10,345,345.3554

Strict mode

By default, fcal will not throw exception if you try to use operations between different types or different units

But with strict mode

const fcal = new Fcal();
fcal.setStrict(true)
try {
  var value = fcal.evaluate('23% + 34 cm + 1');
} catch (e) {
  if (e instanceof FcalError) {
    console.log(e.info());
  }

/*
err: Unexpected '+' operation between different types (unit, number)
| 23% + 34 cm + 1
| ^^^^^^^^^^^^^^^
*/

Using expression

You can change state of expression , re evaluate it

const { Fcal } = require('fcal');

const exp = new Fcal().expression('PI * radius cm ^ 2');

exp.setValues({ radius: 8 });

console.log(exp.evaluate()); // 201.06192982974676726 Centimeters

exp.setValues({ radius: 10 });

console.log(exp.evaluate()); // 314.15926535897932385 Centimeters

exp.setValues({ radius: Infinity });

console.log(exp.evaluate()); // Infinity Centimeters

🤝 Contributing

Contributions, issues and feature requests are welcome!
Feel free to check issues page.

To contribute

$ git clone https://github.com/5anthosh/fcal
$ npm install

Run tests

$ npm test

Author

👤 Santhosh Kumar

Buy Me A Coffee

📝 License

Copyright © 2019 Santhosh Kumar.
This project is MIT licensed.

FOSSA Status

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].