Calculator
Source on Github
Values
Name | Value | Description | |
---|---|---|---|
Constants
Name | Type | Description |
---|---|---|
True | Boolean | Boolean literal |
False | Boolean | Boolean literal |
i | Complex | The imaginary unit |
Infinity | Number | IEEE floating point infinity |
NegativeInfinity | Number | IEEE floating point -infinity |
NaN | Number | IEEE floating point NaN (Not A Number) value. Note that NaN != NaN |
Random | Number | Random number between 0 and 1. Different every time it's used |
Functions and values are NOT case sensitive
Functions
Name | Signature | Description |
---|---|---|
Abs | Number/Complex → Number | Takes the absolute value or magnitude |
aCos | Number → Number | Arc-Cosine |
aSin | Number → Number | Arc-Sine |
aTan | Number → Number | Arc-Tangent |
Ceiling | Number/Complex → Number/Complex | Rounds up to nearest whole integer |
Cos | Number → Number | Cosine of angle in radians |
Floor | Number/Complex → Number/Complex | Rounds down to nearest whole integer |
IsEven | Number → Boolean | Tests if number is even |
IsNaN | Number → Boolean | Tests if number is NaN(not a number) value |
IsOdd | Number → Boolean | Tests if number is odd |
Ln | Number → Number | Natural logarithm |
Log | Number → Number | Log base 10 |
Max | Number, Number → Number | Largest of two numbers |
Min | Number, Number → Number | Smallest of two numbers |
Random | Number, Number → Number | Random number between min(inclusive) and max(exclusive) |
Rational | Number→ Rational | Attempts to convert and simplify a real number to a rational number |
Round | Number, Number(Optional) → Number | Rounds the given number to the specified precision, or the nearest integer if no second value is provided |
Sin | Number → Number | Sine of angle in radians |
Sqrt | Number → Number/Complex | Principle square root (returns complex when argument is negative) |
Sum | Numbers[ ] → Number | Sums all comma separated parameters |
Tan | Number → Number | Tangent of angle in radians |
Using Variables
Variables are created by assigning a value to them with the let
keyword, or by adding it to the list of variables below the main input. You can then use the variable in any expression. Variables are not case sensitive.
A single let
expression can be used to assign multiple comma separated variables as follows: let x = 1, y = 2, z = 3
the assignment does not return a value
Variables can be assigned to any expression, including other variables. This can be useful in keeping complex equations more simple to read
Variables can be reassigned, though it will generate a warning. You may not, however, reassign reserved words such as true
Number formats
Numbers are assumed to be base 10. If you want to input a binary number, prefix it with 0b or 0x for a hexidecimal number. They will be converted to decimal prior to any calculations.
Complex numbers are limited in both input and output to be base 10 for the imaginary component. If you really want an imaginary hex number for example, you could write something like "0x_AA * i"
Output is displayed as decimal by default, but you can use the select at the top of the page to change that to binary or hex.
Hex and binary inputs may not contain decimal points, though decimal may. Hex and binary output format will use decimal points where required
Hex and binary numbers may both contain as many _ as you need. So 0b10011101 is exactly the same as 0b_1001_1101
Scientific notation is partially supported, within the limits of IEEE double precision floating point numbers.
Operators
NOTE: Operator documentation is incomplete, mostly in regards to types. If in doubt, just try it!
Unary Operators
Position | Op | Name | Types | Description |
---|---|---|---|---|
Prefix | + | Unary plus | Number | Positive Number. Doesn't really do anything |
Prefix | - | Unary minus | Number | Equivelent to * -1 |
Prefix | !, NOT | Unary NOT | Boolean, Number | Inverts a Boolean, and flips the bits on a Number |
Postfix | ! | Factorial | Number | Returns the factorial of an integer |
Postfix | i | Imaginary | Number | Marks a Number as the 'imaginary' component of a complex number. |
Binary Operators
Op | Name | Types | Description |
---|---|---|---|
+ | Add | Number | Adds the arguments |
- | Subtract | Number | Subtracts the rhs from the lhs |
* | Multiply | Number | Multiplies the arguments |
/ | Divide | Number | Divides lhs by rhs. Produces Rational where possible |
^ | Power | Number | Raises lhs to the rhs power |
AND, &, && | AND | Boolean, Number | AND between two Booleans, or bitwise AND between two Numbers |
OR, || | OR | Boolean, Number | OR between two Booleans, or bitwise OR between two Numbers |
XOR | XOR | Boolean, Number | XOR between two Booleans, or bitwise XOR between two Numbers |
MOD, % | Modulus | Number | Remainder after integer division |
==, = | Equal | ANY | Equal to, returns Boolean |
!=, <> | Not Equal | ANY | Not equal to, returns Boolean |
< | Less than | Number | Less than, returns Boolean |
<= | Less than or equal to | Number | Less than or equal, returns Boolean |
> | Greater than | Number | Greater than, returns Boolean |
>= | Greater than or equal to | Number | Greater than or equal, returns Boolean |
Special Operators
Op | Name | Types | Description |
---|---|---|---|
| | | Absolute | Number | Returns the absolute of the number between the | Number | |
( ) | Parentheses | ANY | Used for controling precedence |
, | Comma | ANY | Used for separating arguments to a function |
Color Legend
- Number: Real numbers including integers and decimals, as well as special values like NaN, Infinity, and NegativeInfinity
- Rational: Rational numbers represented as a fraction eg. 1/3
- Boolean: True/False only
- Complex: Numbers consisting of a real component and an imaginary component (denoted by i)
- Error: Issues causing the calculator to malfunction
- Warning: Issues which may cause unexpected results, but the calculator will attempt to continue through
To see how it's working under the hood, you can try out the lexer and parser components on their own: