The response has been limited to 50k tokens of the smallest files in the repo. You can remove this limitation by
removing the max tokens filter.
├── .github
└── workflows
│ └── ci.yml
├── .gitignore
├── LICENSE
├── LICENSE_THIRDPARTY
├── README.md
├── benchmarks
├── computations-1.ins
├── computations-160.ins
└── run
├── copy.js
├── docs
├── development.md
├── faq.md
├── features.md
├── generate
├── manpage-footer.md
├── manpage-header.md
├── pros-and-cons.md
├── reference-syntax.md
├── reference-units.md
├── template.readme
└── terminal-version.md
├── generate-third-party-licenses.cjs
├── index.dev.js
├── insect.desktop
├── npm-shrinkwrap.json
├── package.json
├── packages.dhall
├── spago.dhall
├── src
├── Insect.purs
└── Insect
│ ├── Environment.purs
│ ├── Format.purs
│ ├── Functions.purs
│ ├── Interpreter.purs
│ ├── Language.purs
│ ├── Parser.purs
│ └── PrettyPrint.purs
├── test.dhall
├── test
└── Main.purs
└── web
├── .htaccess
├── index.html
├── main.css
├── media
├── README.md
├── insect-16x16.png
├── insect-196x196.png
├── insect-32x32.png
├── insect-banner.png
├── insect-banner.svg
├── insect.png
└── insect.svg
├── opensearch.xml
└── third-party-licenses.txt
/.github/workflows/ci.yml:
--------------------------------------------------------------------------------
1 | name: CI
2 |
3 | on:
4 | push:
5 | branches: [master]
6 | pull_request:
7 | branches: [master]
8 |
9 | permissions:
10 | contents: read
11 |
12 | jobs:
13 | build:
14 | runs-on: ubuntu-latest
15 | steps:
16 | - uses: actions/checkout@v3
17 |
18 | - name: Cache PureScript dependencies
19 | uses: actions/cache@v3
20 | with:
21 | key: ${{ runner.os }}-spago-${{ hashFiles('**/*.dhall') }}
22 | path: |
23 | .spago
24 | output
25 |
26 | - uses: actions/setup-node@v3
27 | with:
28 | node-version: "lts/*"
29 |
30 | - name: Install dependencies
31 | run: npm ci
32 |
33 | - name: Build Insect
34 | run: npm run build
35 |
36 | - name: Check that index.cjs runs successfully
37 | run: ./index.cjs '1 + 1'
38 |
39 | - name: Run tests
40 | run: npm test
41 |
42 | - name: Generate README
43 | uses: docker://pandoc/core:3.1
44 | with:
45 | entrypoint: ./docs/generate
46 |
47 | - name: Check generated README is up to date
48 | run: |
49 | if [ -n "$(git status --porcelain README.md)" ]; then
50 | echo 'There is a mismatch between the autogenerated `README.md` file and the source files in the `docs` directory. If you have edited `README.md` directly, please modify the files in `docs` instead, then run `./docs/generate`. If you already modified the files in `docs`, please run `./docs/generate`.'
51 | echo 'Note that you need to have Pandoc (https://pandoc.org) installed to run `./docs/generate`. You can find the Pandoc version used by Insect in `.github/workflows/ci.yml` (note that the patch version is intentionally not specified in the workflow file, but it'\''s okay for you to have it).'
52 | echo
53 | echo "Here's the diff:"
54 | git diff README.md
55 | exit 1
56 | fi
57 |
58 | - name: Generate third-party licenses
59 | run: ./generate-third-party-licenses.cjs
60 |
61 | - name: Check generated third-party licenses list is up to date
62 | run: |
63 | if [ -n "$(git status --porcelain LICENSE_THIRDPARTY web/third-party-licenses.txt)" ]; then
64 | echo 'There is a mismatch between the autogenerated third-party license list and what running `generate-third-party-licenses.cjs` generates. If you have edited LICENSE_THIRDPARTY or web/third-party-licenses.txt directly, please revert those changes. Otherwise, please run `node generate-third-party-licenses.cjs` locally and commit the changes to the license list to Git.'
65 | exit 1
66 | fi
67 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | /node_modules/
2 | /output/
3 | /.spago/
4 | /.psc*
5 | /.psa*
6 | /index.cjs
7 | /docs/insect.1
8 | /web/*.js
9 | /web/terminal.css
10 | /benchmarks/results/
11 | /benchmarks/results.json
12 | /benchmarks/results.md
13 |
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | MIT License
2 |
3 | Copyright (c) 2018 David Peter
4 |
5 | Permission is hereby granted, free of charge, to any person obtaining a copy
6 | of this software and associated documentation files (the "Software"), to deal
7 | in the Software without restriction, including without limitation the rights
8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 | copies of the Software, and to permit persons to whom the Software is
10 | furnished to do so, subject to the following conditions:
11 |
12 | The above copyright notice and this permission notice shall be included in all
13 | copies or substantial portions of the Software.
14 |
15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21 | SOFTWARE.
22 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | ## Note: Please consider using the follow-up project instead: [Numbat](https://github.com/sharkdp/numbat).
2 |
3 | you can read more about why Insect has been rewritten from scratch [here](https://github.com/sharkdp/numbat/blob/master/assets/reasons-for-rewriting-in-rust.md).
4 |
5 | ---
6 |
7 | <!--
8 |
9 | --- IMPORTANT --- IMPORTANT --- IMPORTANT ---
10 |
11 | Do not edit this README file directly. Edit
12 | the files in the `docs` folder instead.
13 |
14 | --- IMPORTANT --- IMPORTANT --- IMPORTANT ---
15 |
16 | -->
17 |
18 | 
19 |
20 | A high-precision scientific calculator with full support for physical units.
21 |
22 | Contents
23 | --------
24 |
25 | - [Documentation](#documentation)
26 | - [Reference](#reference)
27 | - [Pros and cons](#pros-and-cons)
28 | - [FAQ](#faq)
29 | - [Terminal version](#terminal-version)
30 | - [Development](#development)
31 | - [Maintainers](#maintainers)
32 |
33 | ## Documentation
34 |
35 | - **Evaluate mathematical expressions**:
36 |
37 | 1920/16*9
38 | 2^32
39 | sqrt(1.4^2 + 1.5^2) * cos(pi/3)^2
40 |
41 | - **Operators**: addition (`+`), subtraction (`-`), multiplication
42 | (`*`, `·`, `×`), division (`/`, `÷`, `per`), exponentiation (`^`,
43 | `**`). Full list: see [*Reference*](#reference) below.
44 |
45 | - **Mathematical functions**: `abs`, `acos`, `acosh`,
46 | `acot`/`arccotangent`, `acoth`/`archypcotangent`,
47 | `acsc`/`arccosecant`, `acsch`/`archypcosecant`, `arcsecant`,
48 | `asech`/`archypsecant`, `asin`, `asinh`, `atan2`, `atan`, `atanh`,
49 | `ceil`, `cos`, `cosh`, `cot`/`cotangent`, `coth`/`hypcotangent`,
50 | `csc`/`cosecant`, `csch`/`hypcosecant`, `exp`, `floor`,
51 | `fromCelsius`, `fromFahrenheit`, `gamma`, `ln`, `log10`, `log`,
52 | `maximum`, `mean`, `minimum`, `round`, `secant`, `sech`/`hypsecant`,
53 | `sin`, `sinh`, `sqrt`, `tan`, `tanh`, `toCelsius`, `toFahrenheit`.
54 |
55 | - **High-precision numeric type** with *30* significant digits that
56 | can handle *very* large (or small) exponents like *10^(10^10)*.
57 |
58 | - **Exponential notation**: `6.022e23`.
59 |
60 | - **Hexadecimal, octal and binary number input**:
61 |
62 | 0xFFFF
63 | 0b1011
64 | 0o32
65 | 0x2.F
66 | 0o5p3
67 |
68 | - **Physical units**: parsing and handling, including metric prefixes:
69 |
70 | 2 min + 30 s
71 | 40 kg * 9.8 m/s^2 * 150 cm
72 | sin(30°)
73 |
74 | - **Supported units**: see [*Reference*](#reference) section below.
75 |
76 | - **Implicit conversions**: `15 km/h * 30 min` evaluates to `7.5 km`.
77 |
78 | - **Useful error messages**:
79 |
80 | > 2 watts + 4 newton meter
81 |
82 | Conversion error:
83 | Cannot convert unit N·m (base units: kg·m²·s⁻²)
84 | to unit W (base units: kg·m²·s⁻³)
85 |
86 | - **Explicit unit conversions**: the `->` conversion operator (aliases:
87 | `→`, `➞`, `to`):
88 |
89 | 60 mph -> m/s
90 | 500 km/day -> km/h
91 | 1 mrad -> degree
92 | 52 weeks -> days
93 | 5 in + 2 ft -> cm
94 | atan(30 cm / 2 m) -> degree
95 | 6 Mbit/s * 1.5 h -> GB
96 |
97 | - **Variable assignments**:
98 |
99 | Example: mass of the earth
100 |
101 | r = 6000km
102 | vol = 4/3 * pi * r^3
103 | density = 5 g/cm^3
104 | vol * density -> kg
105 |
106 | Example: oscillation period of a pendulum
107 |
108 | len = 20 cm
109 | 2pi*sqrt(len/g0) -> ms
110 |
111 | - **Predefined constants** (type `list` to see them all): speed of
112 | light (`c`), Planck's constant (`h_bar`), electron mass
113 | (`electronMass`), elementary charge (`elementaryCharge`), magnetic
114 | constant (`µ0`), electric constant (`eps0`), Bohr magneton (`µ_B`),
115 | Avogadro's constant (`N_A`), Boltzmann constant (`k_B`),
116 | gravitational acceleration (`g0`), ideal gas constant (`R`), ...
117 |
118 | - **Last result**: you can use `ans` (answer) or `_` to refer to the
119 | result of the last calculation.
120 |
121 | - **User-defined functions**:
122 |
123 | Example: kinetic energy
124 |
125 | kineticEnergy(mass, speed) = 0.5 * mass * speed^2 -> kJ
126 |
127 | kineticEnergy(800 kg, 120 km/h)
128 |
129 | Example: barometric formula
130 |
131 | P0 = 1 atm
132 | T0 = fromCelsius(15)
133 | tempGradient = 0.65 K / 100 m
134 |
135 | pressure(height) = P0 * (1 - tempGradient * height / T0)^5.255 -> hPa
136 |
137 | pressure(1500 m)
138 |
139 | - **Sums and products**:
140 |
141 | Syntax:
142 |
143 | sum(<expression>, <index-variable>, <from>, <to>)
144 | product(<expression>, <index-variable>, <from>, <to>)
145 |
146 | Examples:
147 |
148 | # sum of the first ten squares
149 | sum(k^2, k, 1, 10)
150 |
151 | # the factorial of n as the product 1 × 2 × ... × n
152 | myFactorial(n) = product(k, k, 1, n)
153 |
154 | - **Unicode support**:
155 |
156 | λ = 2 × 300 µm
157 | ν = c/λ → GHz
158 |
159 | - **And more**: tab completion, command history (arrow keys,
160 | `Ctrl`+`R`), pretty printing, syntax highlighting, ...
161 |
162 | ## Reference
163 |
164 | - Operators (ordered by precedence: high to low)
165 |
166 | | Operator | Syntax |
167 | |---------------------------|----------------------|
168 | | factorial | `!` |
169 | | square, cube, ... | `²`, `³`, `⁻¹`, ... |
170 | | exponentiation | `^`, `**` |
171 | | multiplication (implicit) | *whitespace* |
172 | | modulo | `%` |
173 | | division | `per` |
174 | | division | `/`, `÷` |
175 | | multiplication (explicit) | `*`, `·`, `×` |
176 | | subtraction | `-` |
177 | | addition | `+` |
178 | | unit conversion | `->`, `→`, `➞`, `to` |
179 | | assignment | `=` |
180 |
181 | Note that *implicit* multiplication has a higher precedence than
182 | division, i.e. `50 cm / 2 m` will be parsed as `50 cm / (2 m)`.
183 |
184 | - Commands
185 |
186 | | Command | Syntax |
187 | |--------------------------|--------------------|
188 | | help text | `help`, `?` |
189 | | list of variables | `list`, `ls`, `ll` |
190 | | reset environment | `reset` |
191 | | clear screen | `clear`, `cls` |
192 | | copy result to clipboard | `copy`, `cp` |
193 | | quit (CLI) | `quit`, `exit` |
194 |
195 | - Supported units (remember that you can use tab completion).
196 |
197 | All SI-accepted units support metric prefixes and [binary
198 | prefixes](https://en.wikipedia.org/wiki/Binary_prefix) (`MiB`, `GiB`,
199 | ...).
200 |
201 | | Unit | Syntax |
202 | |------------------------------------------------------------------------------|-----------------------------------------------------------------------------|
203 | | [Ampere](https://en.wikipedia.org/wiki/Ampere) | `amperes`, `ampere`, `A` |
204 | | [Ångström](https://en.wikipedia.org/wiki/Ångström) | `angstroms`, `angstrom`, `Å` |
205 | | [Astronomical unit](https://en.wikipedia.org/wiki/Astronomical_unit) | `AU`, `au`, `astronomicalunits`, `astronomicalunit` |
206 | | [Atmosphere](https://en.wikipedia.org/wiki/Atmosphere_(unit)) | `atm` |
207 | | [Bar](https://en.wikipedia.org/wiki/Bar_(unit)) | `bars`, `bar` |
208 | | [Barn](https://en.wikipedia.org/wiki/Barn_(unit)) | `barns`, `barn` |
209 | | [Becquerel](https://en.wikipedia.org/wiki/Becquerel) | `becquerels`, `becquerel`, `Bq` |
210 | | [Bel](https://en.wikipedia.org/wiki/Decibel) | `bels`, `bel` |
211 | | [Bit](https://en.wikipedia.org/wiki/Bit) | `bits`, `bit` |
212 | | [Bits per second](https://en.wikipedia.org/wiki/Data_rate_units) | `bps` |
213 | | [British thermal unit](https://en.wikipedia.org/wiki/British_thermal_unit) | `BTU` |
214 | | [Byte](https://en.wikipedia.org/wiki/Byte) | `Bytes`, `bytes`, `Byte`, `byte`, `B`, `Octets`, `octets`, `Octet`, `octet` |
215 | | [Calorie](https://en.wikipedia.org/wiki/Calorie) | `calories`, `calorie`, `cal` |
216 | | [Candela](https://en.wikipedia.org/wiki/Candela) | `candelas`, `candela`, `cd` |
217 | | [Coulomb](https://en.wikipedia.org/wiki/Coulomb) | `coulombs`, `coulomb`, `C` |
218 | | [Cup](https://en.wikipedia.org/wiki/Cup_(unit)) | `cups`, `cup` |
219 | | [DPI](https://en.wikipedia.org/wiki/Dots_per_inch) | `dpi` |
220 | | [Day](https://en.wikipedia.org/wiki/Day) | `days`, `day`, `d` |
221 | | [Degree](https://en.wikipedia.org/wiki/Degree_(angle)) | `degrees`, `degree`, `deg`, `°` |
222 | | [Dot](https://en.wikipedia.org/wiki/Dots_per_inch) | `dots`, `dot` |
223 | | [Electronvolt](https://en.wikipedia.org/wiki/Electronvolt) | `electronvolts`, `electronvolt`, `eV` |
224 | | [Euro](https://en.wikipedia.org/wiki/Euro) | `euros`, `euro`, `EUR`, `€` |
225 | | [Farad](https://en.wikipedia.org/wiki/Farad) | `farads`, `farad`, `F` |
226 | | [Fluid ounce](https://en.wikipedia.org/wiki/Fluid_ounce) | `fluidounces`, `fluidounce`, `floz` |
227 | | [Foot](https://en.wikipedia.org/wiki/Foot_(unit)) | `feet`, `foot`, `ft` |
228 | | [Fortnight](https://en.wikipedia.org/wiki/Fortnight) | `fortnights`, `fortnight` |
229 | | [Frame](https://en.wikipedia.org/wiki/Film_frame) | `frames`, `frame` |
230 | | [Frames per second](https://en.wikipedia.org/wiki/Frame_rate) | `fps` |
231 | | [Furlong](https://en.wikipedia.org/wiki/Furlong) | `furlongs`, `furlong` |
232 | | [Gallon](https://en.wikipedia.org/wiki/Gallon) | `gallons`, `gallon`, `gal` |
233 | | [Gauss](https://en.wikipedia.org/wiki/Gauss_(unit)) | `gauss` |
234 | | [Gram](https://en.wikipedia.org/wiki/Gram) | `grams`, `gram`, `grammes`, `gramme`, `g` |
235 | | [Gray](https://en.wikipedia.org/wiki/Gray_(unit)) | `grays`, `gray`, `Gy` |
236 | | [Hectare](https://en.wikipedia.org/wiki/Hectare) | `hectares`, `hectare`, `ha` |
237 | | [Henry](https://en.wikipedia.org/wiki/Henry_(unit)) | `henrys`, `henries`, `henry`, `H` |
238 | | [Hertz](https://en.wikipedia.org/wiki/Hertz) | `hertz`, `Hz` |
239 | | [Hogshead](https://en.wikipedia.org/wiki/Hogshead) | `hogsheads`, `hogshead` |
240 | | [Hour](https://en.wikipedia.org/wiki/Hour) | `hours`, `hour`, `hr`, `h` |
241 | | [Inch](https://en.wikipedia.org/wiki/Inch) | `inches`, `inch`, `in` |
242 | | [Joule](https://en.wikipedia.org/wiki/Joule) | `joules`, `joule`, `J` |
243 | | [Katal](https://en.wikipedia.org/wiki/Katal) | `katals`, `katal`, `kat` |
244 | | [Knot](https://en.wikipedia.org/wiki/Knot_(unit)) | `knots`, `knot`, `kn`, `kt` |
245 | | [Kelvin](https://en.wikipedia.org/wiki/Kelvin) | `kelvins`, `kelvin`, `K` |
246 | | [Light-year](https://en.wikipedia.org/wiki/Light-year) | `lightyears`, `lightyear`, `ly` |
247 | | [Liter](https://en.wikipedia.org/wiki/Liter) | `liters`, `liter`, `litres`, `litre`, `L`, `l` |
248 | | [Lumen](https://en.wikipedia.org/wiki/Lumen_(unit)) | `lumens`, `lumen`, `lm` |
249 | | [Lux](https://en.wikipedia.org/wiki/Lux) | `lux`, `lx` |
250 | | [Meter](https://en.wikipedia.org/wiki/Meter) | `meters`, `meter`, `metres`, `metre`, `m` |
251 | | [Mile](https://en.wikipedia.org/wiki/Mile) | `miles`, `mile` |
252 | | [Miles per hour](https://en.wikipedia.org/wiki/Miles_per_hour) | `mph` |
253 | | [Millimeter of mercury](https://en.wikipedia.org/wiki/Millimeter_of_mercury) | `mmHg` |
254 | | [Minute](https://en.wikipedia.org/wiki/Minute) | `minutes`, `minute`, `min` |
255 | | [Molal](https://en.wikipedia.org/wiki/Molality#Unit) | `molals`, `molal` |
256 | | [Molar](https://en.wikipedia.org/wiki/Molar_concentration#Units) | `molars`, `molar` |
257 | | [Mole](https://en.wikipedia.org/wiki/Mole_(unit)) | `moles`, `mole`, `mol` |
258 | | [Month](https://en.wikipedia.org/wiki/Month) | `months`, `month` |
259 | | [Nautical mile](https://en.wikipedia.org/wiki/Nautical_mile) | `M`, `NM`, `nmi` |
260 | | [Newton](https://en.wikipedia.org/wiki/Newton_(unit)) | `newtons`, `newton`, `N` |
261 | | [Ohm](https://en.wikipedia.org/wiki/Ohm) | `ohms`, `ohm`, `Ω` |
262 | | [Ounce](https://en.wikipedia.org/wiki/Ounce) | `ounces`, `ounce`, `oz` |
263 | | [PPI](https://en.wikipedia.org/wiki/Pixels_per_inch) | `ppi` |
264 | | [Parsec](https://en.wikipedia.org/wiki/Parsec) | `parsecs`, `parsec`, `pc` |
265 | | [Parts-per-million](https://en.wikipedia.org/wiki/Parts-per_notation) | `ppm` |
266 | | [Parts-per-billion](https://en.wikipedia.org/wiki/Parts-per_notation) | `ppb` |
267 | | [Parts-per-trillion](https://en.wikipedia.org/wiki/Parts-per_notation) | `ppt` |
268 | | [Parts-per-quadrillion](https://en.wikipedia.org/wiki/Parts-per_notation) | `ppq` |
269 | | [Pascal](https://en.wikipedia.org/wiki/Pascal_(unit)) | `pascals`, `pascal`, `Pa` |
270 | | [Percent](https://en.wikipedia.org/wiki/Parts-per_notation) | `percent`, `pct` |
271 | | [Person](https://en.wiktionary.org/wiki/person) | `persons`, `person`, `people` |
272 | | [Piece](https://en.wiktionary.org/wiki/piece) | `pieces`, `piece` |
273 | | [Pint](https://en.wikipedia.org/wiki/Pint) | `pints`, `pint` |
274 | | [Pixel](https://en.wikipedia.org/wiki/Pixel) | `pixels`, `pixel`, `px` |
275 | | [Pound-force](https://en.wikipedia.org/wiki/Pound_%28force%29) | `pound_force`, `lbf` |
276 | | [Pound](https://en.wikipedia.org/wiki/Pound_(mass)) | `pounds`, `pound`, `lb` |
277 | | [Psi](https://en.wikipedia.org/wiki/Pounds_per_square_inch) | `psi` |
278 | | [RPM](https://en.wikipedia.org/wiki/RPM) | `RPM`, `rpm` |
279 | | [Radian](https://en.wikipedia.org/wiki/Radian) | `radians`, `radian`, `rad` |
280 | | [Rod](https://en.wikipedia.org/wiki/Rod_(unit)) | `rods`, `rod` |
281 | | [Second](https://en.wikipedia.org/wiki/Second) | `seconds`, `second`, `sec`, `s` |
282 | | [Siemens](https://en.wikipedia.org/wiki/Siemens_(unit)) | `siemens`, `S` |
283 | | [Sievert](https://en.wikipedia.org/wiki/Sievert) | `sieverts`, `sievert`, `Sv` |
284 | | [Tablespoon](https://en.wikipedia.org/wiki/Tablespoon) | `tablespoons`, `tablespoon`, `tbsp` |
285 | | [Teaspoon](https://en.wikipedia.org/wiki/Teaspoon) | `teaspoons`, `teaspoon`, `tsp` |
286 | | [Tesla](https://en.wikipedia.org/wiki/Tesla_(unit)) | `teslas`, `tesla`, `T` |
287 | | [Thou](https://en.wikipedia.org/wiki/Thousandth_of_an_inch) | `thou`, `mils`, `mil` |
288 | | [Tonne](https://en.wikipedia.org/wiki/Tonne) | `tonnes`, `tonne`, `tons`, `ton`, `t` |
289 | | [US Dollar](https://en.wikipedia.org/wiki/USD) | `dollars`, `dollar`, `USD`, `
max tokens
The response has been limited to 50k tokens of the smallest files in the repo. You can remove this limitation by
removing the max tokens filter.
|
290 | | [Volt](https://en.wikipedia.org/wiki/Volt) | `volts`, `volt`, `V` |
291 | | [Watt-hour](https://en.wikipedia.org/wiki/Kilowatt_hour) | `Wh` |
292 | | [Watt](https://en.wikipedia.org/wiki/Watt) | `watts`, `watt`, `W` |
293 | | [Weber](https://en.wikipedia.org/wiki/Weber_(unit)) | `webers`, `weber`, `Wb` |
294 | | [Week](https://en.wikipedia.org/wiki/Week) | `weeks`, `week` |
295 | | [Yard](https://en.wikipedia.org/wiki/Yard) | `yards`, `yard`, `yd` |
296 | | [Gregorian year](https://en.wikipedia.org/wiki/Gregorian_year) | `years`, `year` |
297 | | [Julian year](https://en.wikipedia.org/wiki/Julian_year_(astronomy)) | `julianYears`, `julianYear` |
298 |
299 | ## Pros and cons
300 |
301 | **Reasons to use Insect**
302 |
303 | - Insect is **open-source**.
304 | - There is a [web version](https://Insect.sh/) that requires **no
305 | installation**.
306 | - With both browser and terminal versions available, Insect is truly
307 | **cross-platform**.
308 | - Insect has *first-class* support for **physical units**, including
309 | metric and binary prefixes. While evaluating your calculation, Insect
310 | ensures that you did not accidentally make any mistakes in combining
311 | the physical quantities.
312 | - Insect supports an
313 | [**interactive**](https://en.wikipedia.org/wiki/REPL) style with its
314 | readline-like interface. There is a saved history that can be browsed
315 | by pressing the up and down arrow keys. The history is also searchable
316 | via *Ctrl-R*.
317 | - Insect's syntax is rather strict. The parser does not try to be
318 | "smart" on syntactically incorrect input, so there shouldn't be any
319 | surprises - and you can trust the result of your calculation. The
320 | parsed user input is always pretty-printed for a quick double-check.
321 | - Insect is written in [PureScript](http://www.purescript.org/) and
322 | therefore benefits from all the safety guarantees that a strictly
323 | typed functional programming language gives you.
324 | - The source code of
325 | [purescript-quantities](https://github.com/sharkdp/purescript-quantities)
326 | (the underlying library for physical units) as well as the code of
327 | Insect itself is **extensively tested**.
328 |
329 | **Reasons to choose an alternative**
330 |
331 | - Insect is a scientific calculator. It's not a computer algebra system
332 | that solves differential equations or computes integrals. Try
333 | *[WolframAlpha](http://www.wolframalpha.com/)* instead.
334 | - There is no graphical user interface with buttons for each action
335 | (*x²*, *1/x*, *DEG/RAD*, etc.).
336 | *[Qalculate!](http://qalculate.github.io/)* is a fantastic tool that
337 | supports both text as well as graphical input.
338 | - Insect supports a huge range of physical units: all [SI
339 | units](https://en.wikipedia.org/wiki/International_System_of_Units),
340 | all non-SI units that are accepted by SI as well as most units of the
341 | imperial and US customary systems (and many more). However, if you
342 | need something even more comprehensive, try *[GNU
343 | units](https://www.gnu.org/software/units/)*.
344 | - Insect is not a general-purpose programming language. You could try
345 | *[Frink](https://frinklang.org/)*.
346 | - Insect does not have a special mode for hexadecimal, octal, or binary
347 | numbers (yet), though it does support inputting them.
348 |
349 | ## FAQ
350 |
351 | - Why are Celsius and Fahrenheit not supported?
352 |
353 | In contrast to the SI unit of temperature, the
354 | [Kelvin](https://en.wikipedia.org/wiki/Kelvin), and to all other
355 | units, Celsius and Fahrenheit both require an additive offset when
356 | converting into and from other temperature units. This additive offset
357 | leads to all kinds of ambiguities when performing calculations in
358 | these units. Adding two temperatures in Celsius, for example, is only
359 | meaningful if one of them is seen as an offset value (rather than as
360 | an absolute temperature). Insect is primarily a scientific calculator
361 | (as opposed to a unit conversion tool) and therefore focuses on
362 | getting physical calculations right.
363 |
364 | Even though *°C* and *°F* are not supported as built-in units, there
365 | are helper functions to convert to and from Celsius (and Fahrenheit):
366 |
367 | - `fromCelsius` takes a **scalar value** that represents a temperature
368 | in Celsius and returns a corresponding **temperature in Kelvin**:
369 |
370 | > fromCelsius(0)
371 |
372 | = 273.15 K
373 |
374 | > k_B * fromCelsius(23) to meV
375 |
376 | = 25.5202 meV
377 |
378 | - `toCelsius` takes a **temperature in Kelvin** and returns a **scalar
379 | value** that represents the corresponding temperature in Celsius:
380 |
381 | > toCelsius(70 K)
382 |
383 | = -203.15
384 |
385 | > toCelsius(25 meV / k_B)
386 |
387 | = 16.963
388 |
389 | - Why is `1/2 x` parsed as `1/(2x)`?
390 |
391 | *Implicit* multiplication (without an explicit multiplication sign)
392 | has a higher precedence than division (see [operator precedence
393 | rules](#reference)). This is by design, in order to parse inputs like
394 | `50 cm / 2 m` as `(50 cm) / (2 m)`. If you meant *½ · x*, write
395 | `1/2 * x`.
396 |
397 | - What is the internal numerical precision?
398 |
399 | By default, Insect shows 6 significant digits in the result of the
400 | calculation. However, the internal numerical precision is much higher
401 | (30 digits).
402 |
403 | - How does the conversion operator work?
404 |
405 | The conversion operator `->` attempts to convert the physical quantity
406 | on its left hand side to the *unit of the expression* on its right
407 | hand side. This means that you can write an arbitrary expression on
408 | the right hand side (but only the unit part will be extracted). For
409 | example:
410 |
411 | # simple unit conversion:
412 | > 120 km/h -> mph
413 |
414 | = 74.5645 mi/h
415 |
416 | # expression on the right hand side:
417 | > 120 m^3 -> km * m^2
418 |
419 | = 0.12 m²·km
420 |
421 | # convert x1 to the same unit as x2:
422 | > x1 = 50 km / h
423 | > x2 = 3 m/s -> x1
424 |
425 | x2 = 10.8 km/h
426 |
427 | - What is the relation between the units `RPM`, `rad/s`, `deg/s` and
428 | `Hz`?
429 |
430 | The unit [`RPM`](https://en.wikipedia.org/wiki/Revolutions_per_minute)
431 | (revolutions per minute) is defined via `1 RPM = 1 / minute` where the
432 | `1` on the right hand side symbolizes "1 revolution".
433 |
434 | As the base unit is the same (`1 / second`), `RPM` can be converted to
435 | `rad / s`, `deg / s` or `Hz`. Note, however, that `1 RPM` does *not*
436 | equal `2π rad / min` or `360° / min` or `1 Hz`, as some might expect.
437 | If you're interested in computing the traversed angle of something
438 | that rotates with a given number of revolutions per minute, you need
439 | to multiply by `2π rad` or `360°` because:
440 |
441 | 1 RPM · (360°/revolution) = (1 revolution / minute) · (360° / revolution) = 360° / minute
442 |
443 | ## Terminal version
444 |
445 | In addition to the web interface, there is also a command-line version
446 | (supporting Node.js 10 and later) which can by installed via
447 | [npm](https://www.npmjs.com/package/insect):
448 |
449 | npm install -g insect
450 |
451 | Note that you should almost always never run this as root or with
452 | `sudo`. If the command fails due to permission issues, [set up a prefix
453 | directory](https://github.com/sindresorhus/guides/blob/master/npm-global-without-sudo.md#install-npm-packages-globally-without-sudo-on-macos-and-linux)
454 | and call `npm install` as a user instead.
455 |
456 | For Arch Linux, there is an [AUR
457 | package](https://aur.archlinux.org/packages/insect/):
458 |
459 | yaourt -S insect
460 |
461 | For macOS, there is a [Homebrew
462 | formula](https://formulae.brew.sh/formula/insect):
463 |
464 | brew install insect
465 |
466 | For Android, install [Termux](https://termux.com/) from
467 | [F-Droid](https://f-droid.org/packages/com.termux/). Install Node.js in
468 | Termux and then install `insect` from npm:
469 |
470 | pkg install nodejs-lts
471 | npm install -g insect
472 |
473 | ## Development
474 |
475 | Insect is written in PureScript (see the [Getting
476 | Started](https://github.com/purescript/documentation/blob/master/guides/Getting-Started.md)
477 | guide). First, install all dependencies:
478 |
479 | npm install
480 |
481 | To start the web version:
482 |
483 | npm start
484 |
485 | To build a bundled JavaScript file that you can run from the terminal
486 | (note that this builds the web version too):
487 |
488 | npm run build
489 |
490 | To run the `index.cjs` file which the previous command creates:
491 |
492 | node index.cjs
493 | # Or simply on Un*x
494 | ./index.cjs
495 |
496 | Note that it's not possible to just move this file anywhere and then run
497 | it there, since it depends on packages in `node_modules`.
498 |
499 | Insect comes with a comprehensive set of [unit tests](test/Main.purs).
500 | To run them:
501 |
502 | npm test
503 |
504 | Note that Node.js 12 or above is required to work on/build Insect
505 | (despite Insect itself requiring only Node.js 10 or later to run). If
506 | you don't have or want to install Node.js 12 or later, you can use the
507 | following Dockerfile to build or run Insect on Node.js 18:
508 |
509 | ``` Dockerfile
510 | FROM node:18
511 |
512 | WORKDIR /usr/src/insect
513 |
514 | COPY . .
515 |
516 | RUN npm install && \
517 | npm run build
518 |
519 | CMD ["node", "index.cjs"]
520 | ```
521 |
522 | After creating the image (`docker build -t sharkdp/insect .`), you can
523 | create the container and copy out the build artifacts:
524 |
525 | docker create sharkdp/insect:latest
526 | # copy SHA (e.g. 71f0797703e8)
527 | docker cp 71f0797703e8:/usr/src/insect/index.cjs .
528 | docker cp -r 71f0797703e8:/usr/src/insect/node_modules .
529 |
530 | To directly run Insect inside Docker (paying a heavy startup time
531 | penalty), you can use:
532 |
533 | docker run -it --rm -v ~/.local/share/insect-history:/root/.local/share/insect-history sharkdp/insect:latest
534 |
535 | ## Maintainers
536 |
537 | - [sharkdp](https://github.com/sharkdp)
538 | - [mhmdanas](https://github.com/mhmdanas)
539 |
--------------------------------------------------------------------------------
/benchmarks/computations-1.ins:
--------------------------------------------------------------------------------
1 | 1+1
2 |
--------------------------------------------------------------------------------
/benchmarks/computations-160.ins:
--------------------------------------------------------------------------------
1 | 1920 / 16 * 9
2 | 40000 km / c -> ms
3 | list
4 | 2 min + 30 s
5 | sin(30 deg)
6 | 6 Mbit/s * 1.5 h -> GB
7 | r = 80 cm
8 | pi * r^2 -> m^2
9 | 1920 / 16 * 9
10 | 40000 km / c -> ms
11 | list
12 | 2 min + 30 s
13 | sin(30 deg)
14 | 6 Mbit/s * 1.5 h -> GB
15 | r = 80 cm
16 | pi * r^2 -> m^2
17 | 1920 / 16 * 9
18 | 40000 km / c -> ms
19 | list
20 | 2 min + 30 s
21 | sin(30 deg)
22 | 6 Mbit/s * 1.5 h -> GB
23 | r = 80 cm
24 | pi * r^2 -> m^2
25 | 1920 / 16 * 9
26 | 40000 km / c -> ms
27 | list
28 | 2 min + 30 s
29 | sin(30 deg)
30 | 6 Mbit/s * 1.5 h -> GB
31 | r = 80 cm
32 | pi * r^2 -> m^2
33 | 1920 / 16 * 9
34 | 40000 km / c -> ms
35 | list
36 | 2 min + 30 s
37 | sin(30 deg)
38 | 6 Mbit/s * 1.5 h -> GB
39 | r = 80 cm
40 | pi * r^2 -> m^2
41 | 1920 / 16 * 9
42 | 40000 km / c -> ms
43 | list
44 | 2 min + 30 s
45 | sin(30 deg)
46 | 6 Mbit/s * 1.5 h -> GB
47 | r = 80 cm
48 | pi * r^2 -> m^2
49 | 1920 / 16 * 9
50 | 40000 km / c -> ms
51 | list
52 | 2 min + 30 s
53 | sin(30 deg)
54 | 6 Mbit/s * 1.5 h -> GB
55 | r = 80 cm
56 | pi * r^2 -> m^2
57 | 1920 / 16 * 9
58 | 40000 km / c -> ms
59 | list
60 | 2 min + 30 s
61 | sin(30 deg)
62 | 6 Mbit/s * 1.5 h -> GB
63 | r = 80 cm
64 | pi * r^2 -> m^2
65 | 1920 / 16 * 9
66 | 40000 km / c -> ms
67 | list
68 | 2 min + 30 s
69 | sin(30 deg)
70 | 6 Mbit/s * 1.5 h -> GB
71 | r = 80 cm
72 | pi * r^2 -> m^2
73 | 1920 / 16 * 9
74 | 40000 km / c -> ms
75 | list
76 | 2 min + 30 s
77 | sin(30 deg)
78 | 6 Mbit/s * 1.5 h -> GB
79 | r = 80 cm
80 | pi * r^2 -> m^2
81 | 1920 / 16 * 9
82 | 40000 km / c -> ms
83 | list
84 | 2 min + 30 s
85 | sin(30 deg)
86 | 6 Mbit/s * 1.5 h -> GB
87 | r = 80 cm
88 | pi * r^2 -> m^2
89 | 1920 / 16 * 9
90 | 40000 km / c -> ms
91 | list
92 | 2 min + 30 s
93 | sin(30 deg)
94 | 6 Mbit/s * 1.5 h -> GB
95 | r = 80 cm
96 | pi * r^2 -> m^2
97 | 1920 / 16 * 9
98 | 40000 km / c -> ms
99 | list
100 | 2 min + 30 s
101 | sin(30 deg)
102 | 6 Mbit/s * 1.5 h -> GB
103 | r = 80 cm
104 | pi * r^2 -> m^2
105 | 1920 / 16 * 9
106 | 40000 km / c -> ms
107 | list
108 | 2 min + 30 s
109 | sin(30 deg)
110 | 6 Mbit/s * 1.5 h -> GB
111 | r = 80 cm
112 | pi * r^2 -> m^2
113 | 1920 / 16 * 9
114 | 40000 km / c -> ms
115 | list
116 | 2 min + 30 s
117 | sin(30 deg)
118 | 6 Mbit/s * 1.5 h -> GB
119 | r = 80 cm
120 | pi * r^2 -> m^2
121 | 1920 / 16 * 9
122 | 40000 km / c -> ms
123 | list
124 | 2 min + 30 s
125 | sin(30 deg)
126 | 6 Mbit/s * 1.5 h -> GB
127 | r = 80 cm
128 | pi * r^2 -> m^2
129 | 1920 / 16 * 9
130 | 40000 km / c -> ms
131 | list
132 | 2 min + 30 s
133 | sin(30 deg)
134 | 6 Mbit/s * 1.5 h -> GB
135 | r = 80 cm
136 | pi * r^2 -> m^2
137 | 1920 / 16 * 9
138 | 40000 km / c -> ms
139 | list
140 | 2 min + 30 s
141 | sin(30 deg)
142 | 6 Mbit/s * 1.5 h -> GB
143 | r = 80 cm
144 | pi * r^2 -> m^2
145 | 1920 / 16 * 9
146 | 40000 km / c -> ms
147 | list
148 | 2 min + 30 s
149 | sin(30 deg)
150 | 6 Mbit/s * 1.5 h -> GB
151 | r = 80 cm
152 | pi * r^2 -> m^2
153 | 1920 / 16 * 9
154 | 40000 km / c -> ms
155 | list
156 | 2 min + 30 s
157 | sin(30 deg)
158 | 6 Mbit/s * 1.5 h -> GB
159 | r = 80 cm
160 | pi * r^2 -> m^2
161 |
--------------------------------------------------------------------------------
/benchmarks/run:
--------------------------------------------------------------------------------
1 | #!/bin/sh
2 |
3 | # Get the directory containing this script, see
4 | # https://stackoverflow.com/a/29835459/704831
5 | benchmark_dir=$(CDPATH= cd -- "$(dirname -- "$0")" && pwd)
6 | cd "$benchmark_dir"
7 |
8 | # Check that Hyperfine is installed.
9 | if ! command -v hyperfine > /dev/null 2>&1; then
10 | echo "'hyperfine' does not seem to be installed."
11 | echo "You can get it here: https://github.com/sharkdp/hyperfine"
12 | exit 1
13 | fi
14 |
15 | rm -rf results/
16 | mkdir results/
17 |
18 | hyperfine \
19 | --warmup=5 \
20 | --time-unit=millisecond \
21 | --export-json results/startup.json \
22 | --export-markdown results/startup.md \
23 | --command-name "Startup time (insect '1+1')" \
24 | "node ../index.cjs '1+1'"
25 |
26 | hyperfine \
27 | --warmup=5 \
28 | --time-unit=millisecond \
29 | --export-json results/startup-stdin.json \
30 | --export-markdown results/startup-stdin.md \
31 | --command-name "Startup time, stdin mode (insect < computations-1.ins)" \
32 | "node ../index.cjs < computations-1.ins"
33 |
34 | hyperfine \
35 | --warmup=2 \
36 | --time-unit=millisecond \
37 | --export-json results/evaluation.json \
38 | --export-markdown results/evaluation.md \
39 | --command-name "Evaluation speed (insect < computations-160.ins)" \
40 | "node ../index.cjs < computations-160.ins"
41 |
42 | for benchmark in startup startup-stdin evaluation; do
43 | cat "results/$benchmark.md"
44 | echo
45 | done > results/report.md
46 | cat results/report.md
47 |
--------------------------------------------------------------------------------
/copy.js:
--------------------------------------------------------------------------------
1 | import { copyFileSync } from "fs";
2 |
3 | copyFileSync("node_modules/keyboardevent-key-polyfill/index.js", "web/keyboardevent-key-polyfill.js");
4 | copyFileSync("node_modules/jquery/dist/jquery.min.js", "web/jquery.min.js");
5 | copyFileSync("node_modules/jquery.terminal/js/jquery.terminal.min.js", "web/jquery.terminal.min.js");
6 | copyFileSync("node_modules/jquery.terminal/js/jquery.mousewheel-min.js", "web/jquery.mousewheel-min.js");
7 | copyFileSync("node_modules/jquery.terminal/css/jquery.terminal.min.css", "web/terminal.css");
8 |
--------------------------------------------------------------------------------
/docs/development.md:
--------------------------------------------------------------------------------
1 | Development
2 | -----------
3 |
4 | Insect is written in PureScript (see the [Getting Started](https://github.com/purescript/documentation/blob/master/guides/Getting-Started.md) guide). First, install all dependencies:
5 |
6 | npm install
7 |
8 | To start the web version:
9 |
10 | npm start
11 |
12 | To build a bundled JavaScript file that you can run from the terminal (note that
13 | this builds the web version too):
14 |
15 | npm run build
16 |
17 | To run the `index.cjs` file which the previous command creates:
18 |
19 | node index.cjs
20 | # Or simply on Un*x
21 | ./index.cjs
22 |
23 | Note that it's not possible to just move this file anywhere and then run it
24 | there, since it depends on packages in `node_modules`.
25 |
26 | Insect comes with a comprehensive set of [unit tests](test/Main.purs). To run
27 | them:
28 |
29 | npm test
30 |
31 | Note that Node.js 12 or above is required to work on/build Insect (despite
32 | Insect itself requiring only Node.js 10 or later to run). If you don't have or
33 | want to install Node.js 12 or later, you can use the following Dockerfile to
34 | build or run Insect on Node.js 18:
35 |
36 | ```Dockerfile
37 | FROM node:18
38 |
39 | WORKDIR /usr/src/insect
40 |
41 | COPY . .
42 |
43 | RUN npm install && \
44 | npm run build
45 |
46 | CMD ["node", "index.cjs"]
47 | ```
48 |
49 | After creating the image (`docker build -t sharkdp/insect .`), you can create
50 | the container and copy out the build artifacts:
51 |
52 | docker create sharkdp/insect:latest
53 | # copy SHA (e.g. 71f0797703e8)
54 | docker cp 71f0797703e8:/usr/src/insect/index.cjs .
55 | docker cp -r 71f0797703e8:/usr/src/insect/node_modules .
56 |
57 |
58 | To directly run Insect inside Docker (paying a heavy startup time penalty), you
59 | can use:
60 |
61 | docker run -it --rm -v ~/.local/share/insect-history:/root/.local/share/insect-history sharkdp/insect:latest
62 |
63 | Maintainers
64 | -----------
65 |
66 | * [sharkdp](https://github.com/sharkdp)
67 | * [mhmdanas](https://github.com/mhmdanas)
68 |
--------------------------------------------------------------------------------
/docs/faq.md:
--------------------------------------------------------------------------------
1 | FAQ
2 | ---
3 |
4 | - Why are Celsius and Fahrenheit not supported?
5 |
6 | In contrast to the SI unit of temperature, the [Kelvin](https://en.wikipedia.org/wiki/Kelvin),
7 | and to all other units, Celsius and Fahrenheit both require an additive offset when converting into
8 | and from other temperature units. This additive offset leads to all kinds of ambiguities when
9 | performing calculations in these units. Adding two temperatures in Celsius, for example, is
10 | only meaningful if one of them is seen as an offset value (rather than as an absolute
11 | temperature). Insect is primarily a scientific calculator (as opposed to a unit conversion
12 | tool) and therefore focuses on getting physical calculations right.
13 |
14 | Even though *°C* and *°F* are not supported as built-in units, there are helper functions to
15 | convert to and from Celsius (and Fahrenheit):
16 |
17 | - `fromCelsius` takes a **scalar value** that represents a temperature in Celsius and returns
18 | a corresponding **temperature in Kelvin**:
19 |
20 | ```
21 | > fromCelsius(0)
22 |
23 | = 273.15 K
24 |
25 | > k_B * fromCelsius(23) to meV
26 |
27 | = 25.5202 meV
28 | ```
29 |
30 | - `toCelsius` takes a **temperature in Kelvin** and returns a **scalar value** that
31 | represents the corresponding temperature in Celsius:
32 |
33 | ```
34 | > toCelsius(70 K)
35 |
36 | = -203.15
37 |
38 | > toCelsius(25 meV / k_B)
39 |
40 | = 16.963
41 | ```
42 |
43 | - Why is `1/2 x` parsed as `1/(2x)`?
44 |
45 | *Implicit* multiplication (without an explicit multiplication sign) has a higher precedence
46 | than division (see [operator precedence rules](#reference)). This is by design, in order to
47 | parse inputs like `50 cm / 2 m` as `(50 cm) / (2 m)`. If you meant *½ · x*, write `1/2 * x`.
48 |
49 | - What is the internal numerical precision?
50 |
51 | By default, Insect shows 6 significant digits in the result of the calculation. However,
52 | the internal numerical precision is much higher (30 digits).
53 |
54 | - How does the conversion operator work?
55 |
56 | The conversion operator `->` attempts to convert the physical quantity on its left hand side
57 | to the *unit of the expression* on its right hand side. This means that you can write an
58 | arbitrary expression on the right hand side (but only the unit part will be extracted). For
59 | example:
60 |
61 | ```
62 | # simple unit conversion:
63 | > 120 km/h -> mph
64 |
65 | = 74.5645 mi/h
66 |
67 | # expression on the right hand side:
68 | > 120 m^3 -> km * m^2
69 |
70 | = 0.12 m²·km
71 |
72 | # convert x1 to the same unit as x2:
73 | > x1 = 50 km / h
74 | > x2 = 3 m/s -> x1
75 |
76 | x2 = 10.8 km/h
77 | ```
78 |
79 | - What is the relation between the units `RPM`, `rad/s`, `deg/s` and `Hz`?
80 |
81 | The unit [`RPM`](https://en.wikipedia.org/wiki/Revolutions_per_minute) (revolutions per
82 | minute) is defined via `1 RPM = 1 / minute` where the `1` on the right hand side symbolizes
83 | "1 revolution".
84 |
85 | As the base unit is the same (`1 / second`), `RPM` can be converted to `rad / s`, `deg / s` or
86 | `Hz`. Note, however, that `1 RPM` does *not* equal `2π rad / min` or `360° / min` or `1 Hz`, as
87 | some might expect. If you're interested in computing the traversed angle of something that
88 | rotates with a given number of revolutions per minute, you need to multiply by `2π rad` or
89 | `360°` because:
90 | ```
91 | 1 RPM · (360°/revolution) = (1 revolution / minute) · (360° / revolution) = 360° / minute
92 | ```
93 |
--------------------------------------------------------------------------------
/docs/features.md:
--------------------------------------------------------------------------------
1 | Documentation
2 | -------------
3 |
4 | - **Evaluate mathematical expressions**:
5 |
6 | ```
7 | 1920/16*9
8 | 2^32
9 | sqrt(1.4^2 + 1.5^2) * cos(pi/3)^2
10 | ```
11 |
12 | * **Operators**: addition (`+`), subtraction (`-`),
13 | multiplication (`*`, `·`, `×`), division (`/`, `÷`, `per`),
14 | exponentiation (`^`, `**`). Full list: see [*Reference*](#reference) below.
15 |
16 | * **Mathematical functions**: `abs`, `acos`, `acosh`, `acot`/`arccotangent`,
17 | `acoth`/`archypcotangent`, `acsc`/`arccosecant`, `acsch`/`archypcosecant`, `arcsecant`,
18 | `asech`/`archypsecant`, `asin`, `asinh`, `atan2`, `atan`, `atanh`, `ceil`, `cos`, `cosh`,
19 | `cot`/`cotangent`, `coth`/`hypcotangent`, `csc`/`cosecant`, `csch`/`hypcosecant`, `exp`,
20 | `floor`, `fromCelsius`, `fromFahrenheit`, `gamma`, `ln`, `log10`, `log`, `maximum`, `mean`,
21 | `minimum`, `round`, `secant`, `sech`/`hypsecant`, `sin`, `sinh`, `sqrt`, `tan`, `tanh`,
22 | `toCelsius`, `toFahrenheit`.
23 |
24 | * **High-precision numeric type** with *30* significant digits that can handle
25 | *very* large (or small) exponents like *10^(10^10)*.
26 |
27 | * **Exponential notation**: `6.022e23`.
28 |
29 | * **Hexadecimal, octal and binary number input**:
30 |
31 | ```
32 | 0xFFFF
33 | 0b1011
34 | 0o32
35 | 0x2.F
36 | 0o5p3
37 | ```
38 |
39 | - **Physical units**: parsing and handling, including metric prefixes:
40 |
41 | ```
42 | 2 min + 30 s
43 | 40 kg * 9.8 m/s^2 * 150 cm
44 | sin(30°)
45 | ```
46 |
47 | * **Supported units**: see [*Reference*](#reference) section below.
48 |
49 | * **Implicit conversions**: `15 km/h * 30 min` evaluates to `7.5 km`.
50 |
51 | * **Useful error messages**:
52 |
53 | ```
54 | > 2 watts + 4 newton meter
55 |
56 | Conversion error:
57 | Cannot convert unit N·m (base units: kg·m²·s⁻²)
58 | to unit W (base units: kg·m²·s⁻³)
59 | ```
60 |
61 | - **Explicit unit conversions**: the `->` conversion operator (aliases: `→`, `➞`, `to`):
62 |
63 | ```
64 | 60 mph -> m/s
65 | 500 km/day -> km/h
66 | 1 mrad -> degree
67 | 52 weeks -> days
68 | 5 in + 2 ft -> cm
69 | atan(30 cm / 2 m) -> degree
70 | 6 Mbit/s * 1.5 h -> GB
71 | ```
72 |
73 | - **Variable assignments**:
74 |
75 | Example: mass of the earth
76 | ```
77 | r = 6000km
78 | vol = 4/3 * pi * r^3
79 | density = 5 g/cm^3
80 | vol * density -> kg
81 | ```
82 |
83 | Example: oscillation period of a pendulum
84 | ```
85 | len = 20 cm
86 | 2pi*sqrt(len/g0) -> ms
87 | ```
88 |
89 | * **Predefined constants** (type `list` to see them all): speed of light (`c`),
90 | Planck's constant (`h_bar`), electron mass (`electronMass`), elementary charge
91 | (`elementaryCharge`), magnetic constant (`µ0`), electric constant (`eps0`),
92 | Bohr magneton (`µ_B`), Avogadro's constant (`N_A`), Boltzmann constant
93 | (`k_B`), gravitational acceleration (`g0`), ideal gas constant (`R`), ...
94 |
95 | * **Last result**: you can use `ans` (answer) or `_` to refer to the result of the
96 | last calculation.
97 |
98 | - **User-defined functions**:
99 |
100 | Example: kinetic energy
101 | ```
102 | kineticEnergy(mass, speed) = 0.5 * mass * speed^2 -> kJ
103 |
104 | kineticEnergy(800 kg, 120 km/h)
105 | ```
106 |
107 | Example: barometric formula
108 | ```
109 | P0 = 1 atm
110 | T0 = fromCelsius(15)
111 | tempGradient = 0.65 K / 100 m
112 |
113 | pressure(height) = P0 * (1 - tempGradient * height / T0)^5.255 -> hPa
114 |
115 | pressure(1500 m)
116 | ```
117 |
118 | - **Sums and products**:
119 |
120 | Syntax:
121 | ```
122 | sum(<expression>, <index-variable>, <from>, <to>)
123 | product(<expression>, <index-variable>, <from>, <to>)
124 | ```
125 |
126 | Examples:
127 | ```
128 | # sum of the first ten squares
129 | sum(k^2, k, 1, 10)
130 |
131 | # the factorial of n as the product 1 × 2 × ... × n
132 | myFactorial(n) = product(k, k, 1, n)
133 | ```
134 |
135 | - **Unicode support**:
136 |
137 | ```
138 | λ = 2 × 300 µm
139 | ν = c/λ → GHz
140 | ```
141 |
142 | - **And more**: tab completion, command history (arrow keys, `Ctrl`+`R`), pretty printing, syntax
143 | highlighting, ...
144 |
--------------------------------------------------------------------------------
/docs/generate:
--------------------------------------------------------------------------------
1 | #!/bin/sh
2 |
3 | # Get the directory containing this script, see
4 | # https://stackoverflow.com/a/29835459/704831
5 | docs_dir=$(CDPATH= cd -- "$(dirname -- "$0")" && pwd)
6 | cd "$docs_dir"
7 |
8 | input_format=gfm-hard_line_breaks
9 |
10 | # Generate combined markdown document for README.md
11 | pandoc --from="$input_format" \
12 | --to=gfm-raw_html \
13 | --output=../README.md \
14 | --standalone \
15 | --template=template.readme \
16 | --toc \
17 | features.md \
18 | reference-syntax.md \
19 | reference-units.md \
20 | pros-and-cons.md \
21 | faq.md \
22 | terminal-version.md \
23 | development.md &
24 |
25 | # Generate manpage
26 | pandoc --from="$input_format" \
27 | --to=man \
28 | --output=insect.1 \
29 | --standalone \
30 | --reference-links \
31 | -V section=1 \
32 | -V header="insect - scientific calculator" \
33 | manpage-header.md \
34 | features.md \
35 | reference-syntax.md \
36 | faq.md \
37 | manpage-footer.md &
38 |
39 | wait
40 |
--------------------------------------------------------------------------------
/docs/manpage-footer.md:
--------------------------------------------------------------------------------
1 | # AUTHOR
2 |
3 | Written by David Peter <mail@david-peter.de>.
4 |
5 | # REPORTING BUGS
6 |
7 | Please report bugs on GitHub: <https://github.com/sharkdp/insect>.
8 |
9 | # COPYRIGHT
10 |
11 | insect is MIT-licensed. For details, see <https://github.com/sharkdp/insect>.
12 |
13 | # SEE ALSO
14 |
15 | - Full documentation at <https://github.com/sharkdp/insect>.
16 | - Web version at <https://insect.sh>.
17 |
--------------------------------------------------------------------------------
/docs/manpage-header.md:
--------------------------------------------------------------------------------
1 | # NAME
2 |
3 | insect - **in**teractive **sc**i**e**ntific **c**alcula**t**or
4 |
5 | # SYNOPSIS
6 |
7 | `insect [EXPR]`
8 |
9 | # DESCRIPTION
10 |
11 | *insect* is a high-precision scientific calculator with full support for physical units.
12 |
13 | It can be used in interactive mode by simply calling *insect*. This mode can also be used to read
14 | from a file, by simply piping the file contents via *insect < my-calculation.ins*.
15 | If you want to evaluate just a single expression, pass it as an argument: *insect '70mph to km/h'*.
16 |
--------------------------------------------------------------------------------
/docs/pros-and-cons.md:
--------------------------------------------------------------------------------
1 | Pros and cons
2 | -------------
3 |
4 | **Reasons to use Insect**
5 |
6 | - Insect is **open-source**.
7 | - There is a [web version](https://Insect.sh/) that requires **no installation**.
8 | - With both browser and terminal versions available, Insect is truly **cross-platform**.
9 | - Insect has *first-class* support for **physical units**, including metric and binary prefixes.
10 | While evaluating your calculation, Insect ensures that you did not accidentally make any
11 | mistakes in combining the physical quantities.
12 | - Insect supports an [**interactive**](https://en.wikipedia.org/wiki/REPL) style with its
13 | readline-like interface. There is a saved history that can be browsed by pressing the up and
14 | down arrow keys. The history is also searchable via *Ctrl-R*.
15 | - Insect's syntax is rather strict. The parser does not try to be "smart" on syntactically
16 | incorrect input, so there shouldn't be any surprises - and you can trust the result of your
17 | calculation. The parsed user input is always pretty-printed for a quick double-check.
18 | - Insect is written in [PureScript](http://www.purescript.org/) and therefore benefits from
19 | all the safety guarantees that a strictly typed functional programming language gives you.
20 | - The source code of [purescript-quantities](https://github.com/sharkdp/purescript-quantities)
21 | (the underlying library for physical units) as well as the code of Insect itself is
22 | **extensively tested**.
23 |
24 | **Reasons to choose an alternative**
25 |
26 | - Insect is a scientific calculator. It's not a computer algebra system that solves differential
27 | equations or computes integrals. Try *[WolframAlpha](http://www.wolframalpha.com/)* instead.
28 | - There is no graphical user interface with buttons for each action (*x²*, *1/x*, *DEG/RAD*,
29 | etc.). *[Qalculate!](http://qalculate.github.io/)* is a fantastic tool that supports both
30 | text as well as graphical input.
31 | - Insect supports a huge range of physical units: all
32 | [SI units](https://en.wikipedia.org/wiki/International_System_of_Units), all non-SI units that are
33 | accepted by SI as well as most units of the imperial and US customary systems (and many more).
34 | However, if you need something even more comprehensive, try
35 | *[GNU units](https://www.gnu.org/software/units/)*.
36 | - Insect is not a general-purpose programming language. You could try
37 | *[Frink](https://frinklang.org/)*.
38 | - Insect does not have a special mode for hexadecimal, octal, or binary numbers (yet), though it
39 | does support inputting them.
40 |
--------------------------------------------------------------------------------
/docs/reference-syntax.md:
--------------------------------------------------------------------------------
1 | Reference
2 | ---------
3 |
4 | - Operators (ordered by precedence: high to low)
5 |
6 | | Operator | Syntax |
7 | | ------------------------- | -------------------- |
8 | | factorial | `!` |
9 | | square, cube, ... | `²`, `³`, `⁻¹`, ... |
10 | | exponentiation | `^`, `**` |
11 | | multiplication (implicit) | *whitespace* |
12 | | modulo | `%` |
13 | | division | `per` |
14 | | division | `/`, `÷` |
15 | | multiplication (explicit) | `*`, `·`, `×` |
16 | | subtraction | `-` |
17 | | addition | `+` |
18 | | unit conversion | `->`, `→`, `➞`, `to` |
19 | | assignment | `=` |
20 |
21 | Note that *implicit* multiplication has a higher precedence than division, i.e. `50 cm / 2 m` will be parsed as `50 cm / (2 m)`.
22 |
23 | - Commands
24 |
25 | | Command | Syntax |
26 | | ------------------------ | ------------------ |
27 | | help text | `help`, `?` |
28 | | list of variables | `list`, `ls`, `ll` |
29 | | reset environment | `reset` |
30 | | clear screen | `clear`, `cls` |
31 | | copy result to clipboard | `copy`, `cp` |
32 | | quit (CLI) | `quit`, `exit` |
33 |
--------------------------------------------------------------------------------
/docs/reference-units.md:
--------------------------------------------------------------------------------
1 | - Supported units (remember that you can use tab completion).
2 |
3 | All SI-accepted units support metric prefixes and [binary
4 | prefixes](https://en.wikipedia.org/wiki/Binary_prefix) (`MiB`, `GiB`, ...).
5 |
6 | | Unit | Syntax |
7 | | ---- | ------ |
8 | | [Ampere](https://en.wikipedia.org/wiki/Ampere) | `amperes`, `ampere`, `A` |
9 | | [Ångström](https://en.wikipedia.org/wiki/Ångström) | `angstroms`, `angstrom`, `Å` |
10 | | [Astronomical unit](https://en.wikipedia.org/wiki/Astronomical_unit) | `AU`, `au`, `astronomicalunits`, `astronomicalunit` |
11 | | [Atmosphere](https://en.wikipedia.org/wiki/Atmosphere_(unit)) | `atm` |
12 | | [Bar](https://en.wikipedia.org/wiki/Bar_(unit)) | `bars`, `bar` |
13 | | [Barn](https://en.wikipedia.org/wiki/Barn_(unit)) | `barns`, `barn` |
14 | | [Becquerel](https://en.wikipedia.org/wiki/Becquerel) | `becquerels`, `becquerel`, `Bq` |
15 | | [Bel](https://en.wikipedia.org/wiki/Decibel) | `bels`, `bel` |
16 | | [Bit](https://en.wikipedia.org/wiki/Bit) | `bits`, `bit` |
17 | | [Bits per second](https://en.wikipedia.org/wiki/Data_rate_units) | `bps` |
18 | | [British thermal unit](https://en.wikipedia.org/wiki/British_thermal_unit) | `BTU` |
19 | | [Byte](https://en.wikipedia.org/wiki/Byte) | `Bytes`, `bytes`, `Byte`, `byte`, `B`, `Octets`, `octets`, `Octet`, `octet`|
20 | | [Calorie](https://en.wikipedia.org/wiki/Calorie) | `calories`, `calorie`, `cal` |
21 | | [Candela](https://en.wikipedia.org/wiki/Candela) | `candelas`, `candela`, `cd` |
22 | | [Coulomb](https://en.wikipedia.org/wiki/Coulomb) | `coulombs`, `coulomb`, `C` |
23 | | [Cup](https://en.wikipedia.org/wiki/Cup_(unit)) | `cups`, `cup` |
24 | | [DPI](https://en.wikipedia.org/wiki/Dots_per_inch) | `dpi` |
25 | | [Day](https://en.wikipedia.org/wiki/Day) | `days`, `day`, `d` |
26 | | [Degree](https://en.wikipedia.org/wiki/Degree_(angle)) | `degrees`, `degree`, `deg`, `°` |
27 | | [Dot](https://en.wikipedia.org/wiki/Dots_per_inch) | `dots`, `dot` |
28 | | [Electronvolt](https://en.wikipedia.org/wiki/Electronvolt) | `electronvolts`, `electronvolt`, `eV` |
29 | | [Euro](https://en.wikipedia.org/wiki/Euro) | `euros`, `euro`, `EUR`, `€` |
30 | | [Farad](https://en.wikipedia.org/wiki/Farad) | `farads`, `farad`, `F` |
31 | | [Fluid ounce](https://en.wikipedia.org/wiki/Fluid_ounce) | `fluidounces`, `fluidounce`, `floz` |
32 | | [Foot](https://en.wikipedia.org/wiki/Foot_(unit)) | `feet`, `foot`, `ft` |
33 | | [Fortnight](https://en.wikipedia.org/wiki/Fortnight) | `fortnights`, `fortnight` |
34 | | [Frame](https://en.wikipedia.org/wiki/Film_frame) | `frames`, `frame` |
35 | | [Frames per second](https://en.wikipedia.org/wiki/Frame_rate) | `fps` |
36 | | [Furlong](https://en.wikipedia.org/wiki/Furlong) | `furlongs`, `furlong` |
37 | | [Gallon](https://en.wikipedia.org/wiki/Gallon) | `gallons`, `gallon`, `gal` |
38 | | [Gauss](https://en.wikipedia.org/wiki/Gauss_(unit)) | `gauss` |
39 | | [Gram](https://en.wikipedia.org/wiki/Gram) | `grams`, `gram`, `grammes`, `gramme`, `g` |
40 | | [Gray](https://en.wikipedia.org/wiki/Gray_(unit)) | `grays`, `gray`, `Gy` |
41 | | [Hectare](https://en.wikipedia.org/wiki/Hectare) | `hectares`, `hectare`, `ha` |
42 | | [Henry](https://en.wikipedia.org/wiki/Henry_(unit)) | `henrys`, `henries`, `henry`, `H` |
43 | | [Hertz](https://en.wikipedia.org/wiki/Hertz) | `hertz`, `Hz` |
44 | | [Hogshead](https://en.wikipedia.org/wiki/Hogshead) | `hogsheads`, `hogshead` |
45 | | [Hour](https://en.wikipedia.org/wiki/Hour) | `hours`, `hour`, `hr`, `h` |
46 | | [Inch](https://en.wikipedia.org/wiki/Inch) | `inches`, `inch`, `in` |
47 | | [Joule](https://en.wikipedia.org/wiki/Joule) | `joules`, `joule`, `J` |
48 | | [Katal](https://en.wikipedia.org/wiki/Katal) | `katals`, `katal`, `kat` |
49 | | [Knot](https://en.wikipedia.org/wiki/Knot_(unit)) | `knots`, `knot`, `kn`, `kt` |
50 | | [Kelvin](https://en.wikipedia.org/wiki/Kelvin) | `kelvins`, `kelvin`, `K` |
51 | | [Light-year](https://en.wikipedia.org/wiki/Light-year) | `lightyears`, `lightyear`, `ly` |
52 | | [Liter](https://en.wikipedia.org/wiki/Liter) | `liters`, `liter`, `litres`, `litre`, `L`, `l` |
53 | | [Lumen](https://en.wikipedia.org/wiki/Lumen_(unit)) | `lumens`, `lumen`, `lm` |
54 | | [Lux](https://en.wikipedia.org/wiki/Lux) | `lux`, `lx` |
55 | | [Meter](https://en.wikipedia.org/wiki/Meter) | `meters`, `meter`, `metres`, `metre`, `m` |
56 | | [Mile](https://en.wikipedia.org/wiki/Mile) | `miles`, `mile` |
57 | | [Miles per hour](https://en.wikipedia.org/wiki/Miles_per_hour) | `mph` |
58 | | [Millimeter of mercury](https://en.wikipedia.org/wiki/Millimeter_of_mercury) | `mmHg` |
59 | | [Minute](https://en.wikipedia.org/wiki/Minute) | `minutes`, `minute`, `min` |
60 | | [Molal](https://en.wikipedia.org/wiki/Molality#Unit) | `molals`, `molal` |
61 | | [Molar](https://en.wikipedia.org/wiki/Molar_concentration#Units) | `molars`, `molar` |
62 | | [Mole](https://en.wikipedia.org/wiki/Mole_(unit)) | `moles`, `mole`, `mol` |
63 | | [Month](https://en.wikipedia.org/wiki/Month) | `months`, `month` |
64 | | [Nautical mile](https://en.wikipedia.org/wiki/Nautical_mile) | `M`, `NM`, `nmi` |
65 | | [Newton](https://en.wikipedia.org/wiki/Newton_(unit)) | `newtons`, `newton`, `N` |
66 | | [Ohm](https://en.wikipedia.org/wiki/Ohm) | `ohms`, `ohm`, `Ω` |
67 | | [Ounce](https://en.wikipedia.org/wiki/Ounce) | `ounces`, `ounce`, `oz` |
68 | | [PPI](https://en.wikipedia.org/wiki/Pixels_per_inch) | `ppi` |
69 | | [Parsec](https://en.wikipedia.org/wiki/Parsec) | `parsecs`, `parsec`, `pc` |
70 | | [Parts-per-million](https://en.wikipedia.org/wiki/Parts-per_notation) | `ppm` |
71 | | [Parts-per-billion](https://en.wikipedia.org/wiki/Parts-per_notation) | `ppb` |
72 | | [Parts-per-trillion](https://en.wikipedia.org/wiki/Parts-per_notation) | `ppt` |
73 | | [Parts-per-quadrillion](https://en.wikipedia.org/wiki/Parts-per_notation) | `ppq` |
74 | | [Pascal](https://en.wikipedia.org/wiki/Pascal_(unit)) | `pascals`, `pascal`, `Pa` |
75 | | [Percent](https://en.wikipedia.org/wiki/Parts-per_notation) | `percent`, `pct` |
76 | | [Person](https://en.wiktionary.org/wiki/person) | `persons`, `person`, `people` |
77 | | [Piece](https://en.wiktionary.org/wiki/piece) | `pieces`, `piece` |
78 | | [Pint](https://en.wikipedia.org/wiki/Pint) | `pints`, `pint` |
79 | | [Pixel](https://en.wikipedia.org/wiki/Pixel) | `pixels`, `pixel`, `px` |
80 | | [Pound-force](https://en.wikipedia.org/wiki/Pound_%28force%29) | `pound_force`, `lbf` |
81 | | [Pound](https://en.wikipedia.org/wiki/Pound_(mass)) | `pounds`, `pound`, `lb` |
82 | | [Psi](https://en.wikipedia.org/wiki/Pounds_per_square_inch) | `psi` |
83 | | [RPM](https://en.wikipedia.org/wiki/RPM) | `RPM`, `rpm` |
84 | | [Radian](https://en.wikipedia.org/wiki/Radian) | `radians`, `radian`, `rad` |
85 | | [Rod](https://en.wikipedia.org/wiki/Rod_(unit)) | `rods`, `rod` |
86 | | [Second](https://en.wikipedia.org/wiki/Second) | `seconds`, `second`, `sec`, `s` |
87 | | [Siemens](https://en.wikipedia.org/wiki/Siemens_(unit)) | `siemens`, `S` |
88 | | [Sievert](https://en.wikipedia.org/wiki/Sievert) | `sieverts`, `sievert`, `Sv` |
89 | | [Tablespoon](https://en.wikipedia.org/wiki/Tablespoon) | `tablespoons`, `tablespoon`, `tbsp` |
90 | | [Teaspoon](https://en.wikipedia.org/wiki/Teaspoon) | `teaspoons`, `teaspoon`, `tsp` |
91 | | [Tesla](https://en.wikipedia.org/wiki/Tesla_(unit)) | `teslas`, `tesla`, `T` |
92 | | [Thou](https://en.wikipedia.org/wiki/Thousandth_of_an_inch) | `thou`, `mils`, `mil` |
93 | | [Tonne](https://en.wikipedia.org/wiki/Tonne) | `tonnes`, `tonne`, `tons`, `ton`, `t` |
94 | | [US Dollar](https://en.wikipedia.org/wiki/USD) | `dollars`, `dollar`, `USD`, `
max tokens
The response has been limited to 50k tokens of the smallest files in the repo. You can remove this limitation by
removing the max tokens filter.