{"id":17302409,"url":"https://github.com/coriolinus/calc","last_synced_at":"2025-04-13T21:35:46.590Z","repository":{"id":38316537,"uuid":"337139712","full_name":"coriolinus/calc","owner":"coriolinus","description":"CLI calculator app and library","archived":false,"fork":false,"pushed_at":"2023-11-15T09:01:02.000Z","size":132,"stargazers_count":45,"open_issues_count":7,"forks_count":3,"subscribers_count":4,"default_branch":"main","last_synced_at":"2024-04-24T04:13:02.538Z","etag":null,"topics":["calc","calculator","cli","hacktoberfest"],"latest_commit_sha":null,"homepage":"","language":"Rust","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"gpl-3.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/coriolinus.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null}},"created_at":"2021-02-08T16:36:36.000Z","updated_at":"2024-04-10T15:58:32.000Z","dependencies_parsed_at":"2023-11-15T10:24:36.892Z","dependency_job_id":"6b8068bf-1bb7-4378-a32e-9a362a2dfcc9","html_url":"https://github.com/coriolinus/calc","commit_stats":{"total_commits":65,"total_committers":3,"mean_commits":"21.666666666666668","dds":0.06153846153846154,"last_synced_commit":"9de129c957abb6fb87e05d4f4c3473a5de710d12"},"previous_names":[],"tags_count":5,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/coriolinus%2Fcalc","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/coriolinus%2Fcalc/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/coriolinus%2Fcalc/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/coriolinus%2Fcalc/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/coriolinus","download_url":"https://codeload.github.com/coriolinus/calc/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248788312,"owners_count":21161722,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["calc","calculator","cli","hacktoberfest"],"created_at":"2024-10-15T11:47:27.528Z","updated_at":"2025-04-13T21:35:46.562Z","avatar_url":"https://github.com/coriolinus.png","language":"Rust","funding_links":[],"categories":[],"sub_categories":[],"readme":"# `calc`\n\n[![Build and Test Status](https://github.com/coriolinus/calc/workflows/Build%20and%20Test/badge.svg?branch=main)](https://github.com/coriolinus/calc/actions?query=branch%3Amain+workflow%3A%22Build+and+Test%22)\n\nYet another CLI calculator. Inspired by the excellent \u003chttps://github.com/alfredxing/calc\u003e.\n\n## Installation\n\nWith a Rust toolchain in place:\n\n```sh\ncargo install --force calc\n```\n\nAlternately, you can download a precompiled executable of the most recent [release](https://github.com/coriolinus/calc/releases).\n\n## Usage\n\n### Expression Mode\n\n```sh\n$ calc \"1/(2+(3*(4-5)))\"\n-1\n$ calc \"round(12345 / 543)\"\n23\n```\n\nWhen non-flag arguments are present, `calc` interprets them as an expression and evaluates them immediately.\n\n### Shell Mode\n\n```sh\n$ calc\n[0]: 1 + 1\n2\n[1]: 3*(5/(3-4))\n-15\n[2]: 3*pi**2\n29.608813203268074\n[3]: @+1\n30.608813203268074\n[4]: @@@*2\n-30\n[5]: ln(-1)\nNaN\n```\n\nIn the absence of non-flag arguments, `calc` launches a simple shell which just evaluates each line of input.\n\n## Reference\n\n### Data Types\n\nEvery invocation of `calc` interprets all arguments as a single data type. By default, `calc` uses `f64`, but other data types\ncan be chosen by command-line flag:\n\n- `f64` (default): signed 64-bit floating point operations\n- `u64`: unsigned 64-bit integer operations\n- `i64`: signed 64-bit integer operations\n\nNote that the data type chosen will restrict the available operators, functions, and constants. For example, trigonometric operations\nare not available on integers, and bit-shifting operations are not available on floats.\n\n### Numeric Input Format\n\nNumbers may contain `_` characters at any point. Those symbols are ignored; they are for user convenience and readability only.\n\n`calc` can handle inputs in several numeric bases.\n\n- Un-annotated numbers are assumed to be base 10. Example: `123.45`.\n\n  Note: this is the only format which is legal for non-integral numbers.\n\n- Numbers with a `0b` prefix are in base 2. Example: `0b0110_1010`.\n- Numbers with a `0o` prefix are in base 8. Example: `0o755`.\n\n  Note: a leading `0` is not in itself an octal prefix. Example: `0755` equals `0d755`.\n\n- Numbers with a `0d` prefix are in base 10. Example: `1234_5678`.\n- Numbers with a `0x` prefix are in base 16. Example: `0xdead_beef`.\n\nIt is legal to intermix inputs of varying bases.\n\n### Numeric Output Format\n\nThe output format of an expression can be specified by adding a `:` symbol followed by a format\nspecifier to the expression.\n\nThe format specifier can be anything recognized by the [`num-runtime-fmt` crate](https://docs.rs/num-runtime-fmt/0.1.1/num_runtime_fmt/#format-string-grammar).\n\n```sh\n$ calc -u \"0o644 | 0o111 :#o\"\n0o755\n$ calc -u '0o755 \u0026 !0o111 :04o'\n0644\n```\n\n```\n[0]: 0xab :b 4\n1010 1011\n[1]: @[0] \u003e\u003e\u003e 4 :x_4\nb000_0000_0000_000a\n[2]: @ \u0026 0xF :4b\n1010\n```\n\n```\n$ calc pi / 3 :v#04.4\n0d01.0471\n```\n\n### Order of Operations\n\nThe following order of operations is used to resolve expressions:\n\n- Parentheses (`(...)`)\n- Unary Prefix Operators (`-` `!`)\n- Shifts and Exponentiation (`\u003c\u003c` `\u003e\u003e` `\u003c\u003c\u003c` `\u003e\u003e\u003e` `**`)\n- Bitwise operations (`\u0026` `|` `^`)\n- Multiplication and Division (`*` `/` `//` `%`)\n- Addition and Subtraction (`+` `-`)\n\nOperations at the same level of precedence are resolved from left to right.\n\n### Unary Prefix Operators\n\n- `-`: Negation\n- `!`: Bitwise Not\n\n### Infix Operators\n\n- `+`: Addition\n- `-`: Subtraction\n- `*`: Multiplication\n- `/`: Division\n- `//`: Truncating Division: divides, truncating all data after the decimal point.\n- `**`: Exponentiation\n- `%` : Arithmetic remainder\n- `\u003c\u003c`: Left Shift\n- `\u003e\u003e`: Right Shift\n- `\u003c\u003c\u003c`: Wrapping Left Shift (Rotate Left)\n- `\u003e\u003e\u003e`: Wrappping Right Shift (Rotate Right)\n- `\u0026`: Bitwise And\n- `|`: Bitwise Or\n- `^`: Bitwise Xor\n\n### Functions\n\n- `abs`: Absolute Value\n- `ceil`: Smallest integer greater than or equal to the input\n- `floor`: Greatest integer less than or equal to the input\n- `round`: Nearest integer to the input; halfway cases away from 0.0\n- `sin`: Sine\n- `cos`: Cosine\n- `tan`: Tangent\n- `sinh`: Hyperbolic Sine\n- `cosh`: Hyperbolic Cosine\n- `tanh`: Hyperbolic Tangent\n- `asin`: Arcine\n- `acos`: Arccosine\n- `atan`: Arctangent\n- `asinh`: Inverse Hyperbolic Sine\n- `acosh`: Inverse Hyperbolic Cosine\n- `atanh`: Inverse Hyperbolic Tangent\n- `rad`: Convert a number in degrees to radians\n- `dec`: Convert a number in radians to degrees\n- `sqrt`: Square Root\n- `cbrt`: Cube Root\n- `log`: Base-10 Logarithm\n- `lg`: Base-2 Logarithm\n- `ln`: Natural (Base-e) Logarithm\n- `exp`: `e**x`\n\nTrigonometric functions operate on radians.\n\n### Constants\n\n- `e`: Euler's Number\n- `pi`: Archimedes' Constant\n- `π`: Archimedes' Constant\n\n### History\n\nIn shell mode, `calc` keeps the results of all expressions in memory until it is quit.\n\nThe pseudovariable `@` always refers to the result of the previous expression.\nThe pseudovariable `@@` always refers to the result of the expression before the previous.\nAny number of `@` symbols can be chained this way.\n\nSimply chaining `@` symbols can get cumbersome. The syntax `@{N}`, where `N` is an integer,\nrefers to the `N`th previous result. `@{1}` always refers to the result of the previous expression;\nit is equivalent to `@`. `@{3}` refers to the result 3 expressions ago; it is equivalent to `@@@`.\n\nThe pseuaovariable `@[0]` always refers to the result of the first expression in this shell session.\nLikewise, `@[1]` refers to the second, and so on. The shell interface indicates the current expression.\n\n## Warnings\n\n### No Implicit Multiplication\n\nImplicit multiplication is not supported. Use a multiplication operator such as `*`.\n\n### Floating Point Errors\n\nFloating point operations can compound lossily, and `calc` makes no special efforts to guard against\nthis kind of error. For example:\n\n```sh\n$ calc 'sin(rad(45)) - (sqrt(2) / 2)'\n-0.00000000000000011102230246251565\n```\n\n## Crate Structure\n\nThis crate includes both library code and CLI code. The CLI code is all gated behind feature `cli`; the\n`cli` feature is in the default features. This means that the CLI is built by default. However, it is\npossible to use this crate as a library without building any of the CLI code by including in your\n`Cargo.toml`:\n\n```toml\n[dependencies]\ncalc = { version = \"*\", default-features = false }\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcoriolinus%2Fcalc","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fcoriolinus%2Fcalc","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcoriolinus%2Fcalc/lists"}