1(1)                     insect - scientific calculator                     (1)
2
3
4

NAME

6       insect - interactive scientific calculator
7

SYNOPSIS

9       insect [EXPR]
10

DESCRIPTION

12       insect  is a high-precision scientific calculator with full support for
13       physical units.
14
15       It can be used in interactive mode by simply calling insect.  This mode
16       can  also  be  used to read from a file, by simply piping the file con‐
17       tents via insect < my-calculation.ins.  If you want to evaluate just  a
18       single expression, pass it as an argument: insect '70mph to km/h'.
19
20   Documentation
21       · Evaluate mathematical expressions:
22
23                1920/16*9
24                2^32
25                sqrt(1.4^2 + 1.5^2) * cos(pi/3)^2
26
27         · Operators: addition (+), subtraction (-), multiplication (*, ·, ×),
28           division (/, ÷, per), exponentiation (^, **).  Full list: see  Ref‐
29           erence below.
30
31         · Mathematical functions: abs, acos, acosh, asin, asinh, atan, atan2,
32           atanh, ceil, cos, cosh, exp,  floor,  fromCelsius,  fromFahrenheit,
33           gamma,  ln,  log,  log10, maximum, minimum, mean, round, sin, sinh,
34           sqrt, tan, tanh, toCelsius, toFahrenheit.
35
36         · High-precision numeric type with 30  significant  digits  that  can
37           handle very large (or small) exponents like 10^(10^10).
38
39         · Exponential notation: 6.022e23.
40
41       · Physical units: parsing and handling, including metric prefixes:
42
43                2 min + 30 s
44                40 kg * 9.8 m/s^2 * 150 cm
45                sin(30°)
46
47         · Supported units: see Reference section below.
48
49         · Implicit conversions: 15 km/h * 30 min evaluates to 7.5 km.
50
51         · Useful error messages:
52
53                  > 2 watts + 4 newton meter
54
55                  Conversion error:
56                    Cannot convert unit N·m (base units: kg·m²·s⁻²)
57                                to unit W (base units: kg·m²·s⁻³)
58
59       · Explicit unit conversions: the -> conversion operator (aliases: →, ➞,
60         to):
61
62                60 mph -> m/s
63                500 km/day -> km/h
64                1 mrad -> degree
65                52 weeks -> days
66                5 in + 2 ft -> cm
67                atan(30 cm / 2 m) -> degree
68                6 Mbit/s * 1.5 h -> GB
69
70       · Variable assignments:
71
72         Example: mass of the earth
73
74                r = 6000km
75                vol = 4/3 * pi * r^3
76                density = 5 g/cm^3
77                vol * density -> kg
78
79         Example: oscillation period of a pendulum
80
81                len = 20 cm
82                2pi*sqrt(len/g0) -> ms
83
84         · Predefined constants (type list to see them all):  speed  of  light
85           (c),  Planck's constant (h_bar), electron mass (electronMass), ele‐
86           mentary charge (elementaryCharge), magnetic constant (µ0), electric
87           constant  (eps0),  Bohr  magneton (µ_B), Avogadro's constant (N_A),
88           Boltzmann constant (k_B), gravitational  acceleration  (g0),  ideal
89           gas constant (R), ...
90
91         · Last result: you can use ans (answer) to refer to the result of the
92           last calculation.
93
94       · User-defined functions:
95
96         Example: kinetic energy
97
98                kineticEnergy(mass, speed) = 0.5 * mass * speed^2 -> kJ
99
100                kineticEnergy(800 kg, 120 km/h)
101
102         Example: barometric formula
103
104                P0 = 1 atm
105                T0 = fromCelsius(15)
106                tempGradient = 0.65 K / 100 m
107
108                pressure(height) = P0 * (1 - tempGradient * height / T0)^5.255 -> hPa
109
110                pressure(1500 m)
111
112       · Sums and products:
113
114         Syntax:
115
116                sum(<expression>, <index-variable>, <from>, <to>)
117                product(<expression>, <index-variable>, <from>, <to>)
118
119         Examples:
120
121                # sum of the first ten squares
122                sum(k^2, k, 1, 10)
123
124                # the factorial of n as the product 1 × 2 × ... × n
125                myFactorial(n) = product(k, k, 1, n)
126
127       · Unicode support:
128
129                λ = 2 × 300 µm
130                ν = c/λ → GHz
131
132       · And more: tab completion, command history (arrow keys, Ctrl+R), pret‐
133         ty printing, syntax highlighting, ...
134
135   Reference
136       · Operators (ordered by precedence: high to low)
137
138         Operator                    Syntax
139         ──────────────────────────────────────────
140         factorial                   !
141         square, cube, ...           ², ³, ⁻¹, ...
142         exponentiation              ^, **
143         multiplication (implicit)   whitespace
144         modulo                      %
145         division                    per
146         division                    /, ÷
147         multiplication (explicit)   *, ·, ×
148         subtraction                 -
149         addition                    +
150         unit conversion             ->, →, ➞, to
151         assignment                  =
152
153         Note  that implicit multiplication has a higher precedence than divi‐
154         sion, i.e.  50 cm / 2 m will be parsed as 50 cm / (2 m).
155
156       · Commands
157
158         Command             Syntax
159         ─────────────────────────────────
160         help text           help, ?
161         list of variables   list, ls, ll
162         reset environment   reset
163         clear screen        clear, cls
164         quit (CLI)          quit, exit
165
166   FAQ
167       · Why are Celsius and Fahrenheit not supported?
168
169         Compared to the SI unit Kelvin (https://en.wikipedia.org/wiki/Kelvin)
170         and in contrast to all other units, Celsius and Fahrenheit require an
171         additive offset when  converting  into  and  from  other  temperature
172         units.   This  additive offset leads to all kinds of ambiguities when
173         performing calculations in these units.  Adding two  temperatures  in
174         Celsius, for example, is only meaningful if one of them is seen as an
175         offset value (rather than an absolute temperature).  Insect  is  pri‐
176         marily a scientific calculator (as opposed to a unit conversion tool)
177         and therefore focuses on getting physical calculations right.
178
179         Even though °C and °F are not supported as built-in units, there  are
180         helper functions to convert to and from Celsius (and Fahrenheit):
181
182         · fromCelsius  takes  a scalar value that represents a temperature in
183           Celsius and returns a corresponding temperature in Kelvin:
184
185                  > fromCelsius(0)
186
187                     = 273.15 K
188
189                  > k_B * fromCelsius(23) to meV
190
191                     = 25.5202 meV
192
193         · toCelsius takes a temperature in Kelvin and returns a scalar  value
194           that represents the corresponding temperature in Celsius:
195
196                  > toCelsius(70 K)
197
198                     = -203.15
199
200                  > toCelsius(25 meV / k_B)
201
202                     = 16.963
203
204       · Why is 1/2 x parsed as 1/(2x)?
205
206         Implicit multiplication (without an explicit multiplication sign) has
207         a higher precedence than division (see  operator  precedence  rules).
208         This  is  by  design,  in  order  to parse inputs like 50 cm / 2 m as
209         (50 cm) / (2 m).  If you meant ½ · x, write 1/2 * x.
210
211       · What is the internal numerical precision?
212
213         By default, Insect shows 6 significant digits in the  result  of  the
214         calculation.  However, the internal numerical precision is much high‐
215         er (30 digits).
216
217       · How does the conversion operator work?
218
219         The conversion operator -> attempts to convert the physical  quantity
220         on its left hand side to the unit of the expression on its right hand
221         side.  This means that you can write an arbitrary expression  on  the
222         right  hand side (but only the unit part will be extracted).  For ex‐
223         ample:
224
225                # simple unit conversion:
226                > 120 km/h -> mph
227
228                  = 74.5645 mi/h
229
230                # expression on the right hand side:
231                > 120 m^3 -> km * m^2
232
233                  = 0.12 m²·km
234
235                # convert x1 to the same unit as x2:
236                > x1 = 50 km / h
237                > x2 = 3 m/s -> x1
238
239                  x2 = 10.8 km/h
240

AUTHOR

242       Written by David Peter <mail@david-peter.de>.
243

REPORTING BUGS

245       Please report bugs on GitHub: <https://github.com/sharkdp/insect>.
246
248       insect       is       MIT-licensed.        For       details,       see
249       <https://github.com/sharkdp/insect>.
250

SEE ALSO

252       · Full documentation at <https://github.com/sharkdp/insect>.
253
254       · Web-version at <https://insect.sh>.
255
256
257
258                                                                           (1)
Impressum