Skip to content

数式の逆ポーランド記法コンバート。および逆ポーランド記法の演算。

License

Notifications You must be signed in to change notification settings

Aniny21/ReversePolishNotation

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

21 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Reverse Polish Notation

Example.1 Generate rpn

  rpn.Generate("2*(5 + 7)");
  // => 2 5 7 + *

  //# repeated multiplication (exponentiation)
  rpn.Generate("4 ** 3 ** 2");
  // => 4 3 2 ** **

  //# menus sign replace to '_'
  rpn.Generate("~-5*4**(0x0f - 12)**2");
  // => 5 _ ~ 4 15 12 - 2 ** ** *

Example.2 Calculate rpn

  rpn("2 5 7 + *");
  // => 24

  //# exponentiation peoceeds from right to left
  rpn("4 3 2 ** **");
  // => 262144

  rpn("5_~4 15 12-2** ** *");
  // => 1048576

Add operate function

rpn.SetOperate(name, arity, function)

  //# chain method available
  //# define sine and cosine function
  rpn.SetOperate("sin", 1, function(arg1){ return Math.sin(arg1*(Math.PI/180)); })
    .SetOperate("cos", 1, function(arg1){ return Math.cos(arg1*(Math.PI/180)); });

  rpn.Generate("sin(45 + 45)");
  // => 45 45 + sin
  rpn("45 45 + sin");
  // => 1

Supported operator

+ - * / ** % << >> ~ & ^ |

About

数式の逆ポーランド記法コンバート。および逆ポーランド記法の演算。

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • JavaScript 79.8%
  • HTML 20.2%