-
-
Notifications
You must be signed in to change notification settings - Fork 0
Expressions
Expressions that are not preceded by a repl command are interpreted, computed and applied on the current stack just like dc.
In this mode, every token is interpreted as an operation, based on their type:
The following forms are allowed:
1
1.
are equivalent
0.234
.234
are equivalent
1e-2
.01
are equivalent
Additionally, an underscore (_
) could be used anywhere in a number literal.
A unit
is defined as a base unit (length, mass, etc.). Derived units such as molarity should be defined as an unit alias.
Units are denoted by an identifier enclosed by parenthesis (()
).
The following units are defined automatically:
- No Unit:
1
- Mass:
g
. - Volume:
l
. - International Unit (IU):
iu
. - Length:
m
. - Mole:
mol
.
A unit token in RPN mode set the unit of the quantity on top of stack.
If the top of the stack already has a quantity: unitdc will check if they are equivalent, if so a unit conversion would be performed. Otherwise an error will be thrown and evaluation will stop.
To forcefully interpret an existing quantity with unit as another unit, convert it into no unit
((1) operator
) and then convert back to the desired unit.
An derived unit follows the same syntax as an unit, but internally handled as a combination of base units.
The following units are defined automatically:
- Molar:
M
=1 (mol) 1 (l) /
.mM
uM
nM
pM
. - Dalton:
Da
=1 (g) 1 (mol) /
.kDa
- Mass:
mg
ug
ng
pg
. - Volume:
dl
ml
ul
nl
. - Length:
cm
mm
um
nm
. - Mole:
mmol
umol
nmol
pmol
.
For a full list of pre-defined units, see here
The following operators are defined, functionality is equivalent to dc
unless otherwise specified. Necessary unit conversions will be performed and if they are impossible, an error will be thrown and evaluation will stop, stack remains unmodified:
c
d
v
p
n
f
The following operators are defined, functionality is equivalent to dc
unless otherwise specified. Two quantities are popped from the stack and the result is pushed back onto the stack, necessary unit conversions will be performed and if they are impossible, an error will be thrown and evaluation will stop, stack remains unmodified:
+
-
*
/
r
U
: Outputs a summary of the current unit system.
There are two macros defined:
-
@base(xxx)
definesxxx
as a base unit. -
@derived(xxx)
pops two values on the stack, the first one is thescale
and the second one is theoffset
, and definesxxx
to be a derived unit equivalent toscale
* x +offset
.