https://github.com/sharkdp/insect Skip to content Sign up * Product + Features + Mobile + Actions + Codespaces + Packages + Security + Code review + Issues + Integrations + GitHub Sponsors + Customer stories * Team * Enterprise * Explore + Explore GitHub + Learn and contribute + Topics + Collections + Trending + Learning Lab + Open source guides + Connect with others + The ReadME Project + Events + Community forum + GitHub Education + GitHub Stars program * Marketplace * Pricing + Plans + Compare plans + Contact Sales + Education [ ] * # In this repository All GitHub | Jump to | * No suggested jump to results * # In this repository All GitHub | Jump to | * # In this user All GitHub | Jump to | * # In this repository All GitHub | Jump to | Sign in Sign up {{ message }} sharkdp / insect Public * * Notifications * Fork 103 * Star 2.6k High precision scientific calculator with support for physical units insect.sh MIT License 2.6k stars 103 forks Star Notifications * Code * Issues 26 * Pull requests 2 * Actions * Security * Insights More * Code * Issues * Pull requests * Actions * Security * Insights This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository. master Switch branches/tags [ ] Branches Tags Could not load branches Nothing to show {{ refName }} default View all branches Could not load tags Nothing to show {{ refName }} default View all tags 4 branches 34 tags Code Latest commit @sharkdp sharkdp Add bottom margin for terminal, closes #281 ... ab14ba8 Mar 7, 2022 Add bottom margin for terminal, closes #281 ab14ba8 Git stats * 382 commits Files Permalink Failed to load latest commit information. Type Name Latest commit message Commit time docs update docs to include 'copy' command Oct 19, 2020 src Pretty print function definition Mar 4, 2021 test Pretty print function definition Mar 4, 2021 web Add bottom margin for terminal, closes #281 Mar 7, 2022 .gitignore Update jquery.terminal version Jan 25, 2020 .npmignore Update .npmignore Jul 13, 2019 .travis.yml Remove manual purescript installation from travis, it's already insta... Sep 27, 2020 LICENSE updated licence to 2018 Oct 6, 2018 README.md Add installation instructions for Android Nov 6, 2020 build.sh Run browserify and copy after install Oct 12, 2018 copy.js Add pre-publish build step to fix installing insect from npm Sep 27, 2020 index.js Implement insectrc (closes #107) Feb 13, 2021 package-lock.json Bump ini from 1.3.5 to 1.3.8 Jan 29, 2022 package.json Add bottom margin for terminal, closes #281 Mar 7, 2022 packages.dhall move to using psc-package and npm for bower deps Jan 25, 2020 psc-package.json move to using psc-package and npm for bower deps Jan 25, 2020 View code Contents Documentation Reference Pros and cons FAQ Terminal version Development README.md insect A high precision scientific calculator with full support for physical units. Try the web version here: https://insect.sh Contents * Documentation * Reference * Pros and cons * FAQ * Terminal version * Development Documentation * Evaluate mathematical expressions: 1920/16*9 2^32 sqrt(1.4^2 + 1.5^2) * cos(pi/3)^2 + Operators: addition (+), subtraction (-), multiplication (*, *, x), division (/, /, per), exponentiation (^, **). Full list: see Reference below. + Mathematical functions: abs, acos, acosh, asin, asinh, atan, atan2, atanh, ceil, cos, cosh, exp, floor, fromCelsius, fromFahrenheit, gamma, ln, log, log10, maximum, minimum, mean, round, sin, sinh, sqrt, tan, tanh, toCelsius, toFahrenheit. + High-precision numeric type with 30 significant digits that can handle very large (or small) exponents like 10^(10^10). + Exponential notation: 6.022e23. * Physical units: parsing and handling, including metric prefixes: 2 min + 30 s 40 kg * 9.8 m/s^2 * 150 cm sin(30deg) + Supported units: see Reference section below. + Implicit conversions: 15 km/h * 30 min evaluates to 7.5 km. + Useful error messages: > 2 watts + 4 newton meter Conversion error: Cannot convert unit N*m (base units: kg*m2*s-2) to unit W (base units: kg*m2*s-3) * Explicit unit conversions: the -> conversion operator (aliases: -, , to): 60 mph -> m/s 500 km/day -> km/h 1 mrad -> degree 52 weeks -> days 5 in + 2 ft -> cm atan(30 cm / 2 m) -> degree 6 Mbit/s * 1.5 h -> GB * Variable assignments: Example: mass of the earth r = 6000km vol = 4/3 * pi * r^3 density = 5 g/cm^3 vol * density -> kg Example: oscillation period of a pendulum len = 20 cm 2pi*sqrt(len/g0) -> ms + Predefined constants (type list to see them all): speed of light (c), Planck's constant (h_bar), electron mass (electronMass), elementary charge (elementaryCharge), magnetic constant (u0), electric constant (eps0), Bohr magneton (u_B), Avogadro's constant (N_A), Boltzmann constant (k_B), gravitational acceleration (g0), ideal gas constant (R), ... + Last result: you can use ans (answer) to refer to the result of the last calculation. * User-defined functions: Example: kinetic energy kineticEnergy(mass, speed) = 0.5 * mass * speed^2 -> kJ kineticEnergy(800 kg, 120 km/h) Example: barometric formula P0 = 1 atm T0 = fromCelsius(15) tempGradient = 0.65 K / 100 m pressure(height) = P0 * (1 - tempGradient * height / T0)^5.255 -> hPa pressure(1500 m) * Sums and products: Syntax: sum(, , , ) product(, , , ) Examples: # sum of the first ten squares sum(k^2, k, 1, 10) # the factorial of n as the product 1 x 2 x ... x n myFactorial(n) = product(k, k, 1, n) * Unicode support: l = 2 x 300 um n = c/l - GHz * And more: tab completion, command history (arrow keys, Ctrl+R), pretty printing, syntax highlighting, ... Reference * Operators (ordered by precedence: high to low) Operator Syntax factorial ! square, cube, ... 2, 3, -1, ... exponentiation ^, ** multiplication (implicit) whitespace modulo % division per division /, / multiplication (explicit) *, *, x subtraction - addition + unit conversion ->, -, , to assignment = Note that implicit multiplication has a higher precedence than division, i.e. 50 cm / 2 m will be parsed as 50 cm / (2 m). * Commands Command Syntax help text help, ? list of variables list, ls, ll reset environment reset clear screen clear, cls copy result to clipboard copy, cp quit (CLI) quit, exit * Supported units (remember that you can use tab completion). All SI-accepted units support metric prefixes. In addition, binary prefixes (MiB, GiB, ...) are also supported. Unit Syntax Ampere amperes, ampere, A Angstrom angstrom, A Astronomical unit AU, au, astronomicalunits, astronomicalunit Atmosphere atm Bar bar Barn barn Becquerel becquerel, Bq Bel bel Bit bits, bit Bits per second bps British thermal unit BTU Byte Bytes, bytes, Byte, byte, B, Octets, octets, Octet, octet Calorie calories, calorie, cal Candela candela, cd Coulomb coulomb, C Cup cups, cup DPI dpi Day days, day, d Degree degrees, degree, deg, deg Dot dots, dot Electronvolt electronvolt, eV Euro euros, euro, EUR, EUR Farad farad, F Fluid ounce fluidounces, fluidounce, floz Foot feet, foot, ft Fortnight fortnights, fortnight Frame frames, frame Frames per second fps Furlong furlongs, furlong Gallon gallons, gallon, gal Gauss gauss Gram grams, gram, grammes, gramme, g Gray gray, Gy Hectare hectare, ha Henry henrys, henries, henry, H Hertz hertz, Hz Hogshead hogsheads, hogshead Hour hours, hour, h Inch inches, inch, in Joule joules, joule, J Katal katal, kat Kelvin kelvin, K Light-year lightyears, lightyear, ly Liter liters, liter, litres, litre, L, l Lumen lumen, lm Lux lux, lx Meter meters, meter, metres, metre, m Mile miles, mile Miles per hour mph Millimeter of mercury mmHg Minute minutes, minute, min Mole mole, mol Month months, month Newton newton, N Ohm ohms, ohm, O Ounce ounces, ounce, oz PPI ppi Parsec parsecs, parsec, pc Parts-per-million ppm Parts-per-billion ppb Parts-per-trillion ppt Parts-per-quadrillion ppq Pascal pascal, Pa Percent percent, pct Person persons, person, people Piece pieces, piece Pint pints, pint Pixel pixels, pixel, px Pound-force pound_force, lbf Pound pounds, pound, lb Psi psi RPM RPM, rpm Radian radians, radian, rad Rod rods, rod Second seconds, second, sec, s Siemens siemens, S Sievert sievert, Sv Tablespoon tablespoons, tablespoon, tbsp Teaspoon teaspoons, teaspoon, tsp Tesla tesla, T Thou thou, mils, mil Tonne tonnes, tonne, tons, ton, t US Dollar dollars, dollar, USD, $ Volt volts, volt, V Watt-hour Wh Watt watts, watt, W Weber weber, Wb Week weeks, week Yard yards, yard, yd Year years, year Pros and cons Reasons to use Insect * Insect is open source. * There is a web version that requires no installation. * With both browser and terminal versions available, insect is truly cross-platform. * Insect has first-class support for physical units, including metric and binary prefixes. While evaluating your calculation, Insect ensures that you did not accidentally make any mistakes in combining the physical quantities. * Insect supports an interactive style with its readline-based interface. There is a saved history that can be browsed by pressing up- and down keys. The history is also searchable via Ctrl-R. * The syntax of Insect is rather strict. The parser does not try to be "smart" on syntactically incorrect input, so there shouldn't be any surprises - and you can trust the result of your calculation. The parsed user input is always pretty-printed for a quick double-check. * Insect is written in PureScript and therefore benefits from all the safety-guarantees that a strictly-typed functional programming language gives you. * The source code of purescript-quantities (the underlying library for physical units) as well as the code of Insect itself is extensively tested. Reasons to choose an alternative * Insect is a scientific calculator. It's not a computer algebra system that solves differential equations or computes integrals. Try WolframAlpha instead. * There is no graphical user interface with buttons for each action (x2, 1/x, DEG/RAD, etc.). Qalculate! is a fantastic tool that supports both text- as well as graphical input. * Insect supports a huge range of physical units: all SI units, all units that are accepted by SI as well as most units of the imperial and US customary systems (and many more). However, if you need something even more comprehensive, try GNU units. * Insect is not a general-purpose programming language. You could try Frink. * Insect does not have a special mode for hexadecimal or binary numbers (yet). FAQ * Why are Celsius and Fahrenheit not supported? Compared to the SI unit Kelvin and in contrast to all other units, Celsius and Fahrenheit require an additive offset when converting into and from other temperature units. This additive offset leads to all kinds of ambiguities when performing calculations in these units. Adding two temperatures in Celsius, for example, is only meaningful if one of them is seen as an offset value (rather than an absolute temperature). Insect is primarily a scientific calculator (as opposed to a unit conversion tool) and therefore focuses on getting physical calculations right. Even though degC and degF are not supported as built-in units, there are helper functions to convert to and from Celsius (and Fahrenheit): + fromCelsius takes a scalar value that represents a temperature in Celsius and returns a corresponding temperature in Kelvin: > fromCelsius(0) = 273.15 K > k_B * fromCelsius(23) to meV = 25.5202 meV + toCelsius takes a temperature in Kelvin and returns a scalar value that represents the corresponding temperature in Celsius: > toCelsius(70 K) = -203.15 > toCelsius(25 meV / k_B) = 16.963 * Why is 1/2 x parsed as 1/(2x)? Implicit multiplication (without an explicit multiplication sign) has a higher precedence than division (see operator precedence rules). This is by design, in order to parse inputs like 50 cm / 2 m as (50 cm) / (2 m). If you meant 1/2 * x, write 1/2 * x. * What is the internal numerical precision? By default, Insect shows 6 significant digits in the result of the calculation. However, the internal numerical precision is much higher (30 digits). * How does the conversion operator work? The conversion operator -> attempts to convert the physical quantity on its left hand side to the unit of the expression on its right hand side. This means that you can write an arbitrary expression on the right hand side (but only the unit part will be extracted). For example: # simple unit conversion: > 120 km/h -> mph = 74.5645 mi/h # expression on the right hand side: > 120 m^3 -> km * m^2 = 0.12 m2*km # convert x1 to the same unit as x2: > x1 = 50 km / h > x2 = 3 m/s -> x1 x2 = 10.8 km/h * What is the relation between the units RPM, rad/s, deg/s and Hz? The unit RPM (revolutions per minute) is defined via 1 RPM = 1 / minute where the 1 on the right hand side symbolizes "1 revolution". As the base unit is the same (1 / second), RPM can be converted to rad / s, deg / s or Hz. Note, however, that 1 RPM does not equal 2p rad / min or 360deg / min or 1 Hz, as some might expect. If you interested in computing the traversed angle of something that rotates with a given number of revolutions per minute, you need to multiply by 2p rad or 360 deg because: 1 RPM * (360deg/revolution) = (1 revolution / minute) * (360deg / revolution) = 360deg / minute Terminal version In addition to the web interface, there is also a command line version which can by installed via npm: npm install -g insect Note that this might fail if you run it with sudo. Instead, set up a prefix directory and call npm install as a user. If you prefer not to install nodejs and npm, you can use one of the standalone binaries on the release page. For Arch Linux, there is a package on AUR: yaourt -S insect On Fedora 28+, you can install insect from the official sources: sudo dnf install insect For Fedora versions 26 and 27, you need to enable this copr repository: sudo dnf copr enable fnux/insect For macOS, there is a Homebrew package: brew install insect For Android, install Termux from Google Play or F-Droid. Install nodejs in Termux and then install insect. pkg install nodejs-lts npm install -g insect Development Build Status Insect is written in PureScript (see Getting Started guide). You can install all dependencies and build the whole project by running: npm install npm start Open web/index.html in your browser. Insect comes with a comprehensive set of unit tests. You can run them by calling npm test About High precision scientific calculator with support for physical units insect.sh Topics calculator parser purescript physics web-app units mathematical-expressions terminal-based quantities Resources Readme License MIT License Stars 2.6k stars Watchers 32 watching Forks 103 forks Releases 24 v5.6.0 Latest Oct 24, 2020 + 23 releases Sponsor this project Sponsor Learn more about GitHub Sponsors Used by 9 * @LuisThiamNye * @4cm4k1 * @chronologos * @excitedleigh * @ajmwagar * @RuurdBijlsma * @slak44 + 1 Contributors 26 * @sharkdp * @dependabot[bot] * @n4bb12 * @septatrix * @zelpa * @tomioe * @jimmo * @justinwoo * @colinwahl * @nunomarks * @perryprog + 15 contributors Languages * PureScript 75.9% * HTML 16.3% * JavaScript 4.4% * CSS 2.1% * Other 1.3% * (c) 2022 GitHub, Inc. * Terms * Privacy * Security * Status * Docs * Contact GitHub * Pricing * API * Training * Blog * About You can't perform that action at this time. You signed in with another tab or window. Reload to refresh your session. You signed out in another tab or window. Reload to refresh your session.