GithubHelp home page GithubHelp logo

printfn / fend Goto Github PK

View Code? Open in Web Editor NEW
614.0 10.0 50.0 3.13 MB

Arbitrary-precision unit-aware calculator

Home Page: https://printfn.github.io/fend

License: MIT License

Rust 94.25% Shell 2.41% HTML 0.17% CSS 0.20% JavaScript 0.87% PowerShell 0.49% TypeScript 1.61%
calculator rust units-of-measure hacktoberfest

fend's Introduction

build codecov crates.io downloads

fend icon

fend is an arbitrary-precision unit-aware calculator.

Unique features:

  • Arbitrary-precision arithmetic using rational numbers
  • Full support for complex numbers
  • D&D-style dice rolls
  • Variables
  • Binary, octal, hexadecimal and all other bases between 2 and 36
  • Keep track of units, with support for SI, US and UK customary and many historical units
  • Emacs-style CLI shortcuts
  • Trigonometric functions
  • Lambda calculus

See the manual for more information.

fend is available on the web at printfn.github.io/fend.

Installation

The easiest way to install fend locally is via your package manager:

Package Manager Command
Homebrew brew install fend
MacPorts sudo port install fend
AUR (Arch Linux) yay -Syu aur/fend-bin
AOSC OS oma install fend
Xbps (Void Linux) xbps-install fend
Nix nix-env -iA nixpkgs.fend
Cargo cargo install fend
Windows Package Manager winget install fend
Chocolatey choco install fend
Scoop scoop install fend
Pkgx pkgx fend

Alternatively, you can manually download the latest stable binaries here.

Once fend is installed, run fend to start a REPL session:

$ fend
> 1 ft to cm
30.48 cm
>

Packages

You can find the fend manual here.

Examples

> 5'10" to cm
177.8 cm
> cos (pi/4) + i * (sin (pi/4))
approx. 0.7071067811 + 0.7071067811i
> 0b1001 + 3
0b1100
> 0xffff to decimal
65535
> 100 C to F
210 °F
> temperature = 30 °C
30 °C
> temperature to °F
86 °F
> roll d20
8
> roll 4d6
17

Projects using fend

These are some projects making use of fend:

Feel free to make a pull request to add your own!

License

fend is available under the MIT license. See LICENSE.md for more information.

fend's People

Contributors

albertlarsan68 avatar dependabot[bot] avatar dgalbraith avatar djanatyn avatar eatradish avatar elcste avatar fa993 avatar frectonz avatar haykam821 avatar herbygillot avatar jadedblueeyes avatar khrs avatar lzzzzzt avatar maltet avatar markos-th09 avatar mat-1 avatar michaelessiet avatar miki-tebe avatar mlcui-corp avatar nickgeek avatar printfn avatar probablykasper avatar rhysmdnz avatar sekoiatree avatar techcable avatar tranzystorekk avatar twolodzko avatar xfnw avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

fend's Issues

Scientific notation in output

Allow configuration of the output format (as done with to exact/20dp/etc) but for scientific notation.

This might be possible already, but I can't figure out how to do this.

We might also allow for other notations, like those mentioned in the above Wikipedia article. I would be willing to put some work into this.

Thank You!

Too many arguments

Hey, thanks for the awesome project!

Is there a reason to forbid the following usage?

$ fend 1 + 1

I know I can just do

$ fend "1 + 1"

but it could just work without quotes.

Feature: `at`-styled time arithmetic operations

Description

I frequently use the Unix at command for scheduling jobs to start during dynamic time windows. Often times, it's important to delay the time windows by grouped time deltas. Could I humbly request help from fend to make this easier in shell scripting? Adding time blocks (like at this website ) would make a big QoL improvement for me.

Does this seem like something that is an appropriate feature request?

Incorrect output for recurring digits in senary

6#1 / 7 -> float results in 6#0.0(5), but it should be 6#0.(05).

> 0 + 6#1 / 7 -> 10dp
0.1428571428
> 0 + 6#1 / 6 -> 10dp
0.1666666666
> 6#0 + 6#1 / 7 -> 10dp
6#0.0505050505
> 6#0 + 6#1 / 7 -> float
6#0.0(5)

Use $ in identifiers

I would like to be able to use $ in fend like $200/3 to 2dp to print approx. $66.66.

Logs

Add support for logarithms

Rethink order of operations (multiplication/division)

Consider the three operators:

  • multiplication *
  • division /
  • function application/implicit multiplication/implicit addition (used in sin pi, 3 kg, (2)(4) or 1 1/2).

Current these are all parsed mostly left-to-right, with mostly the same precedence (and a bunch of special cases).

These calculations are correct and should continue working as they do now:

  • 1 3/8 inches
  • 1/2 kg
  • 3pi/2 radians to degrees
  • -sin (pi/2)
  • 5 feet 2 inches

These examples don't do what the user might expect:

  • 1 meter / 5 seconds (parsed as (1 meter / 5) * seconds)
  • sin pi/2 (parsed as (sin pi)/2)

This calculation can't be parsed at all:

  • 3sin 5 (should be equivalent to 3 * (sin 5))

It would be nice to come up with a consistent solution for all these expressions, preferably not involving whitespace.

Improve interactive/noninteractive UI

Interactive:

  • Allow Ctrl+C when waiting for input only when no input has been typed yet
  • Add to history incrementally
  • Exit with Ctrl+D
  • Exit with an error only if the last command caused an error (regardless of its result)
  • Cancel a slow calculation with Ctrl+C

Noninteractive:

  • Used if stdin is a file/pipe/other program, or if there are any command-line arguments
  • Still potentially evaluate stdin
    • echo "1+1"|fend => 2
    • Maybe echo "1+2"|fend "*2" => 6
  • Set error code based on result value (0 is falsy)
  • Don't add to history

Date/Time support

  • Date objects: '2022-01-01' to date
  • Better syntax for creating dates: @1970-01-01
  • ISO 8601 output format
  • Simple date arithmetic: date + 5 days
  • Different date output formats
  • Durations, e.g. 2:23:28.936
    • Parse
    • Output
  • Timestamps syntax?
    • Timezones

Use 'per' in output

7500 per month to per hour should give an answer as per hour instead of hour^-1

Support parsing recurring decimals

  • Support parsing digits in parentheses as part of a number literal
  • Correctly compute the value of recurring digits
    • Support .*(0)
    • Support .(*)
    • .0(*)
    • Support arbitrary recurring decimals
  • Allow 2(e) and 2(ln 5) as multiplication
  • Allow 2 (5) and 2( 5) as multiplication
  • Ensure any outputted recurring digits (incl. in complex numbers) are parsed correctly
  • Fix any integration tests that output recurring digits

Lambdas are being evaluated incorrectly

Input: ((λa.(λb.(λc.(λd.(λe.(λf.(((a (λg.(λh.((b (g (d h))) (g (e h)))))) (λg.(c g))) f))))))) (λa.(λb.(a (a (a b))))))

Expected: (λb.(λc.(λd.(λe.(λf.((b ((b ((b (c (d (d (d f))))) (c (e (d (d f)))))) ((b (c (d (e (d f))))) (c (e (e (d f))))))) ((b ((b (c (d (d (e f))))) (c (e (d (e f)))))) ((b (c (d (e (e f))))) (c (e (e (e f))))))))))))

Actual: \b.(\c.(\d.(\e.(\f.((((((a ((\g.(\h.((((b (((g (((d (h))))))))) (((g (((e (h)))))))))))))) ((\g.((c (g))))))) (f)))))))

The issue is probably that fend’s associativity is wrong (lambdas are supposed to be left-assoc while application is meant to be right-assoc).

Probably relates to #76

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.