GithubHelp home page GithubHelp logo

tiffany352 / rink-rs Goto Github PK

View Code? Open in Web Editor NEW
406.0 13.0 28.0 1.93 MB

Unit conversion tool and library written in rust

Home Page: https://rinkcalc.app/about

License: GNU General Public License v3.0

Rust 91.12% HTML 0.80% JavaScript 1.17% TypeScript 2.10% CSS 1.97% Makefile 0.39% Lua 2.45%
conversion units units-of-measure units-measures-converter measurements calculator calculations dimensional-analysis

rink-rs's Introduction

Rink

codecov crates.io downloads

https://rinkcalc.app/about

Rink is an open source unit-aware calculator. It can be used for physics and engineering calculations, as well as dimensionality analysis.

Rink supports most systems of measurements including SI, CGS, natural, international customary, US customary, UK customary, as well as historical measurements. In addition, Rink supports currency conversions.

Features

  • Arbitrary precision math
  • Shows SI physical quantities
  • Finds applicable SI derived units automatically
  • Detailed error messages
  • Helps with dimensionality analysis, such as by offering unit factorizations and finding units for quantities.
  • Temperature conversions

Describes (hopefully) everything you need to know to use Rink's expression language.

Install

The most common version of Rink is the command line interface rink.

Package Manager Command
Cargo cargo install rink
Pacman pacman -S rink
Nix nix-env -i rink
Scoop scoop install rink

Downloads are also available at https://rinkcalc.app/releases.

Rink is available via a web interface in addition to the terminal-based interface. Useful for doing calculations on mobile.

Examples

How much does it cost to run my computer each year? Say it uses 100 watts for 4 hours per day, and use the US average electricity cost.

> 0.1545$/kWh * 100W * (4 hours / day) to $/year
approx. 22.57196 USD / tropicalyear

If you made a solid sphere of gold the size of the moon, what would the surface gravity be?

> volume of moon * (19.283 g/cm^3) * G / (radius of moon)^2
approx. 9.365338 meter / second^2 (acceleration)
> ans to gravity
approx. 0.9549987 gravity (acceleration)

Ever heard someone joke about Americans measuring fuel efficiency as rods per hogshead? Let's try with the average US car fuel efficiency.

> 9.4 km/l to mpg
approx. 22.11017 mpg (fuel_efficiency)
> 9.4 km/l to rods per hogshead
approx. 445741.0 rod / ushogshead (fuel_efficiency)

And then you wonder, wait, what even are these units anyway?

> hogshead
Definition: ushogshead = 2 liquidbarrel = approx. 238480942.3 millimeter^3 (volume; m^3)
> liquidbarrel
Definition: liquidbarrel = 31.5 usgallon = approx. 119240471.1 millimeter^3 (volume; m^3)
> rod
Definition: rod = 5.5 yard = 5.0292 meter (length; m)

Library Usage

docs.rs

[dependencies]
rink-core = "0.8"

License

Rink source code is licensed under the Mozilla Public License, version 2. See LICENSE-MPL for details.

The data file definitions.units is licensed under the GNU General Public License, version 3. See LICENSE-GPL for details.

Contribution

Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work will grant the rights lined out in the MPL, including larger works with secondary licenses.

If you plan on making edits to definitions.units, check out the documentation here: docs/rink-defs.5.adoc

Changelog

See here: https://rinkcalc.app/releases

rink-rs's People

Contributors

aaron1011 avatar alexalemi avatar bhipple avatar causal-agent avatar deeunderscore avatar delan avatar dependabot[bot] avatar deviant avatar kittywitch avatar kotarac avatar leftshift avatar lluchs avatar lpghatguy avatar murarth avatar orzfly avatar rx14 avatar tiffany352 avatar whitequark avatar yzhs 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  avatar  avatar  avatar

rink-rs's Issues

% interacts weirdly with **

E.g.:

> (100.0860%) ** 365
approx. 1.368568 (dimensionless)
> 100.0860% ** 365
1.00086e-728 (dimensionless)

Use `dirs::cache_dir` instead

Rink stores cached currency data in the config dir which is not the right place for it.

history.txt should probably stay in the config dir but I'm not sure.

Indicate recurring base-N representations

https://en.wikipedia.org/wiki/Repeating_decimal#Extension_to_other_bases

Wikipedia is terrible with math stuff though. I actually found out about these rules from this video, which explains way better:

https://youtu.be/qID2B4MK7Y0?t=673

I think the important rule is this:

If the current remainder is not a multiple of the base, and divides cleanly into base^N - 1 (for base 10, this would be 9, then 99, then 999, and so on), then the remainder represents the N recurring digits.

Base 10 cases

Fraction Divides into Result
1/3 9 / 3 = 3 0.3 recurring
1/7 999 999 / 7 = 142 857 0.142857 recurring
1/9 99 / 9 = 11 0.11 recurring
1/11 99 / 11 = 09 0.09 recurring

Base 2 cases

Fraction Divides into Result
1 / 3 (0b1 / 0b11) 0b11 / 0b11 = 0b01 0b0.01 recurring
1 / 6 (0b1 / 0b110) ? 0b0.001, 01 recurring

Build / Installation problems

I've just discovered this repository and wanted to try it, but I'm not able to build the project. I've tried "cargo install rink", cloning the repo and using "cargo build" and adding it as a dependency to one of my own projects. For every method, there's the following error

running: "cc" "-O0" "-ffunction-sections" "-fdata-sections" "-g" "-m64" "-fPIC" "-o" "/home/user/rink-rs/target/debug/build/openssl-5464f8f6e728c35a/out/src/c_helpers.o" "-c" "src/c_helpers.c"
cargo:warning=src/c_helpers.c:1:25: fatal error: openssl/ssl.h: No such file or directory
cargo:warning=compilation terminated.
ExitStatus(ExitStatus(256))

I've tried using rustc 1.14.0 as well as 1.16.0-nightly on Ubuntu 16.04.

Do you have any hints for me?

Openssl dependency fails to install

If system has OpenSSL v1.0+, dependancy openssl v0.9.24 fails to install. Searching around reveals that openssl v0.10+ fixes this incompatibility.

If I add openssl = "^0.10" to rink Cargo.toml, it installs without issues.

Didn't create a pull request as I'm not familiar with rust and not sure if this is a valid solution.

Feature request: conversion history

I find it rather common that I write some complicated expression, quit rink, and then want to run a slightly modified form of it the next time. I would hugely appreciate a persistent history.

RFE: Support some command line switches, especially -h / --help

Right now rink takes all command line argument(s) as a file to load, and it doesn't deal very well if the file isn't there, perhaps because you innocently tried to use -h to see if there was any command line usage help:

$ rink -h
thread 'main' panicked at 'called `Result::unwrap()` on an `Err` value: Error { repr: Os { code: 2, message: "No such file or directory" } }', src/libcore/result.rs:906:4
note: Run with `RUST_BACKTRACE=1` for a backtrace.

It would be nice if rink supported -h / --help, and also perhaps --version, especially if one or the other reported the URL of the repository (so I could remember to check it every so often for new versions).

Planned features

  • Bignums (probably using the num crate, as it provides complexes of ratios of bigints)
  • Date/time handling
  • Hardcoded conversion of Celsius and Fahrenheit to Kelvin and Rankine (respectively), before any other unit calculations
  • Memory and time limits for IRC bot
  • Complex numbers
  • Currency conversions
  • Built-in functions (log, sin, sqrt, etc.)
  • Point and vector math

Inline CLI usage

rink(1) is proving to be a neat utility, but I only perform quick inlined CLI usage, so echo "..." | rink feels too long, and an alias/function (adding ^D) feels like a poor hack.

Would it make sense, say, to add -i "..." as a way to directly invoke the utility instead of piping it out?

Incorrect divide by zero panic

Inputting the following string will cause a divide by zero error in gmp:

5.2*10^15*300^(3/2)

The expected output is something to the tune of 2.7019993*10^19

input box hidden on rink-web on mobile devices

rink-web looks like this on my phone:
screenshot_2016-10-09-18-02-23

There's no input box. (There's some input because I coped the URL from my desktop.) The hamburger button does nothing. BTW, putting the input box into the header on mobile devices might be a bad idea; e.g. the default Android browser will put the URL box over that part of the page.

Suggestion for improving the UX of the web interface

When someone opens the web interface of Rink they see this:

Screenshot of Rink web app

The input field on that page feels more like a small site-search box that you would use for looking up documentation or similar information than a natural main point of attention and interaction.

For example, compare that to the search boxes on GitHub, crates.io and a whole slew of other websites, where the search box is secondary to what is the main focus of the page you are on.

Screenshot of GitHub

Screenshot of crates.io

And then look at sites like SymPy Gamma and Wolfram|Alpha, where the input box is meant to be the main focus of the page you are on.

Screenshot of SymPy Gamma

Screenshot of Wolfram|Alpha

In my opinion, the user experience of the Rink web interface would improve a lot if it drew inspiration from these two (which in turn basically follow the model of Google and other search engines).

Have a big input field with an "=" button next to it that becomes the main focus of the user when they open the web interface.

Currency endpoint improvements

  • Don't delay responses, return a stale value and update asynchronously. The upstream endpoints are very slow and there's no point in delaying requests, as the upstream endpoints update infrequently.
  • Fix concurrency bug where if there's already a request in flight, it will cause multiple requests to be sent out.
  • Set up proxy caching for the endpoint in the nginx config (this is a server specific task).

I want to be reasonably confident that the endpoint won't fall over once it starts seeing frequent use.

Remove rust-gmp dependency

This dependency makes it impossible to build rink on windows for me, and also makes it impossible to do things like compile to wasm for an offline-cached version of rink-web. There's a few native-rust alternatives these days to look into.

IRC and Matrix reference implementations

Hi,

I noticed that the IRC implementation is no longer maintained.

I'm already maintaining a newer IRC implementation in my own fork, albeit with some pretty breaking changes to the output formatting, but I wouldn't mind maintaining a branch where I could submit the changes upstream without the personalized formatting (although I do disagree with the use of NOTICE over PRIVMSG due to how many clients consider NOTICEs to be "highlights/notifications")

I do have a question, though — I've also recently done a matrix client implementation that I'm willing to maintain for the duration that I'm using Matrix (pardon me for the code quality, it's heavily copied and rushed 😄) and I was wondering if at this point you might prefer out-of-tree implementations you could refer to?

Updated units database

"definition.units" has been updated in latest gnu units (v2.16 of the file, but found inside v2.14 of the source code)

Bits and Bytes all treated as bits

Hi,

There is some odd behavior between bits and bytes, (i.e. GB, Gb, GiB) all being treated as the same unit and converted to bit, where the 3 units are distinctively different units.

Example:
"5 bytes" becomes "40 bit"
"800GB" becomes "6.4 terrabit"

Also as a side note "TB" is recognized as a terrabyte/bit, however "Tb" comes up as a tablespoon. Maybe tablespoon can be changed to "tb" so that "TB" can be consistently used, similarly to gigabytes in the following different units (TB, Tb, TiB).

Error in rink web

The web app doesn't seem to handling it's decades correctly.

For instance 2 pi radius of earth / c returns 133 seconds instead of 133 milliseconds, despite both the radius of earth and speed of light being correct. This does work in the CLI.

Update dependencies to latest versions

  • chrono (significant breaking changes)
    • chrono-tz
    • chrono-humanize
  • serde
    • serde_derive - not needed anymore now that proc macros exist
  • sandboxing -- should be moved into rink-web, also there might be better alternatives for sandboxing than libc rlimit these days
    • ipc-channel (removed)
    • libc (removed)
  • linefeed (significant breaking changes)
  • xml-rs -- should look into replacing this with something that has xpath
  • json -- should use serde for this probably
  • reqwest

"digits" doesn't work

The wiki lists a few examples for usage of the digits modifier:

> 2^128 -> digits
340282366920938463463374607431768211456 (dimensionless)
> 1/7 -> digits 50
1/7, approx. 0.1428571428571428571428571428571428571428571428571428 (dimensionless)
> googol -> digits
10000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 (dimensionless)

However, all of them fail with "No such unit digits" when used on the current master.

Add output artifacts to CI builds

Package managers like Scoop require a pre-built binary in order to distribute an application, and so it's important to start shipping official binaries for the CLI with each release.

Doing it in CI is important because the pre-built binaries should be available for all platforms.

Code coverage is not being updated

This is just a heads up that kcov is not being run in CI

I used your repo as a template when adding code coverage to my own tests and ended up with mkroman/webalert@77ce8b4 as I had several issues with your old approach - the biggest one being that when my crate is a lib, it doesn't seem to just dump the tests in target/debug/<test>, but instead dumped it as executables in target/debug/deps/… along with the built crate bins.

This created a new problem - I couldn't distinguish between tests and the CLI bin, and kcov would run and show code coverage for the failure path of my CLI despite it being untested.

That's when I found cargo-kcov which parses the output of cargo test to distinguish tests from crate bins and then runs them. But unfortunately it seems a lot slower to run than it should be.

Scrape some sort of physical properties database

I tried to do this today, expecting something with densities:

> 3.7 billion l * water -> ton
Conformance error: 7256921/200000, approx. 36.28460 giganewton (force) != 45359237/50000, approx. 907.1847 kilogram (mass)
Suggestions: divide left side by acceleration, multiply right side by acceleration

Then I tried to see what various substance names map to, and it's kind of a mess...

> water
Definition: water = gram force / cm^3 = 9806.65 pascal / meter (kg / m^2 s^2)
> mercury
Definition: mercury = 200.59 g / mol = 0.20059 kilogram / mole (molar_mass; kg / mol)
> milk
Definition: milk = 242 g / uscup = approx. 1022.874 kilogram / meter^3 (density; kg / m^3)
> oil
Definition: oil = 7.5 oz / uscup = approx. 898.6982 kilogram / meter^3 (density; kg / m^3)
> gasoline
Definition: gasoline_HHV = 125000 btu / usgallon = approx. 34.83953 gigapascal (pressure; kg / m s^2)
> air
Definition: air = 78.08 % nitrogen 2 + 20.95 % oxygen 2 + 9340 ppm argon + 400 ppm (carbon + oxygen 2) + 18.18 ppm neon + 5.24 ppm helium + 1.7 ppm (carbon + 4 hydrogen) + 1.14 ppm krypton + 0.55 ppm hydrogen 2 = approx. 0.02896790 kilogram / mole (molar_mass; kg / mol)

Add a web API

It should be possible to run a Rink query using an API like

curl --get -d 'q=kWh/year -> W' https://rinkcalc.app/api/v1/query

(i.e.)

https://rinkcalc.app/api/v1/query?q=...

This might be helpful for people setting up custom bots for running Rink queries or whatever.

Floating point exception

When trying to calculate the following:

(ln(11000)-ln(9600))/log(1+0,038)

The application crashes with floating point exception

This is also seen on the website.

rustc 1.13.0 (2c6933acc 2016-11-07) on x86_64.
I also tested with rustc 1.15.0-nightly (c80c31a50 2016-12-02)
rink is straight from HEAD.

---✂----

-----------------------------------------------------------------------------------------------------------------------[regs]
  RAX: 0x0000000000000000  RBX: 0x0000000000000008  RBP: 0x00007FFFFFFEECA8  RSP: 0x00007FFFFFFEE9B8  o d I t s Z a P c 
  RDI: 0x0000000000000002  RSI: 0x00007FFFFFFEE940  RDX: 0x0000000000000000  RCX: 0x00007FFFF6DE1F5F  RIP: 0x00007FFFF6DE1F5F
  R8 : 0x0000000000000000  R9 : 0x00007FFFFFFEE940  R10: 0x0000000000000008  R11: 0x0000000000000246  R12: 0x00007FFFFFFFB258
  R13: 0x0000000000000000  R14: 0x00007FFFFFFEF201  R15: 0x0000000000000000
  CS: 0033  DS: 0000  ES: 0000  FS: 0000  GS: 0000  SS: 002B				
-----------------------------------------------------------------------------------------------------------------------[code]
=> 0x7ffff6de1f5f <raise+207>:	add    rsp,0x88
   0x7ffff6de1f66 <raise+214>:	mov    eax,r8d
   0x7ffff6de1f69 <raise+217>:	pop    rbx
   0x7ffff6de1f6a <raise+218>:	ret    
   0x7ffff6de1f6b <raise+219>:	nop    DWORD PTR [rax+rax*1+0x0]
   0x7ffff6de1f70 <raise+224>:	mov    rdx,QWORD PTR [rip+0x207011]        # 0x7ffff6fe8f88
   0x7ffff6de1f77 <raise+231>:	neg    eax
   0x7ffff6de1f79 <raise+233>:	mov    DWORD PTR fs:[rdx],eax
-----------------------------------------------------------------------------------------------------------------------------
0x00007ffff6de1f5f in raise () from /usr/lib/libpthread.so.0

Backtrace

#1  0x00007ffff7b578ae in __gmp_invalid_operation () from /usr/lib/libgmp.so.10
#2  0x00007ffff7b72345 in __gmpq_set_d () from /usr/lib/libgmp.so.10
#3  0x000055555572c683 in rink::number::to_string::haec1297263603064 ()
#4  0x0000555555730da4 in rink::number::Number::numeric_value::h4850098f4b2093d6 ()
#5  0x0000555555733076 in rink::number::Number::to_parts::he3c1abf6d0004735 ()
#6  0x00005555557242e7 in rink::eval::_$LT$impl$u20$rink..context..Context$GT$::eval_outer::h60a4e918c72522ff ()
#7  0x000055555576ba02 in rink::one_line::h2e9b2f6ff43e8ecc ()
#8  0x00005555556c5376 in rink::main_interactive::hb160f18d7d736a5b ()
#9  0x00005555556cb819 in rink::main::h948107a286eaccdf ()
#10 0x0000555555800257 in __rust_maybe_catch_panic ()
#11 0x00005555557f6f12 in std::rt::lang_start::h538f8960e7644c80 ()
#12 0x00007ffff683c291 in __libc_start_main () from /usr/lib/libc.so.6
#13 0x00005555556afb6a in _start ()

Rink 0.4.1 has runtime errors

After removing rink 0.4.0, I installed rink 0.4.1 with "cargo install rink", and now I get thousands of lines of error messages when I run rink. :/ This happens under Ubuntu natively, and it happens under Windows on Bash for Windows with that version of Ubuntu too. I've attached an output.txt file containing all of the output.

output.txt

Custom unit definitions

Add a new command define {name} {expr}. Probably also undef {name} and list-defs as well. They'll need to be mentioned in the manual.

Units should be saved to the config directory and be stored in json format (DefEntry's Serialize/Deserialize impl).

Editing the file directly should let you use additional functionality like defining new substances, categories, base units, prefixes.

precedence issue

To reproduce:

> 300g/(58 g/mol)
150/29, approx. 5.172413 mole (amount)
> 300g/(58 g/mol)*(22.4 l/mol)
46875/203, approx. 230.9113 mole^2 / meter^3

Explicit multipication of negative numbers does a sum instead

Perhaps it's just me, but I found the with explicit multiplication and negative numbers to seriously trip up my calculations. The following example should illustrate the problem.


The following calculations work as expected, yielding the correct sum or product with implicit multiplication:

> 3/4  -1
-0.25 (dimensionless)
> 3/4 ( -1)
-0.75 (dimensionless)

However when a users tries to use explicit multiplication to avoid wrapping the negative in parentheses:

 > 3/4 * -1
-0.25 (dimensionless)

This is very unintuitive and for me and probably for others. I would consider it a serious bug to silently eat an explicit operator for multiplication and instead perform a sum. What's more this is not the behavior of frink on which rink seems to be based.

Figuring out how to exit is hard

> ^C
> ^C
> exit()
No such unit exit, did you mean spectral_exitance_frequency?
> ^C
> ^C
> ^C
> ^C
>
Expected term, got eof
> help
For information on how to use Rink, see the manual: https://github.com/tiffany352/rink-rs/wiki/Rink-Manual
> .exit
Expected term, got <Malformed number literal: No digits after decimal point>
> :q
Expected term, got `:`
> quit

update crates.io

Is it time to update crates?

I install this on every single one of my computers, and I tremendously enjoy this tool. The version on Crates is 7 months old, but it seems commits have been happening in the interim.

Infinite loop in complex log

If the following is input, an infinite loop occurs:
log10(-1)

The expected result is 1.36437635 i. If complex numbers won't be supported for a while, could we at least get an error here?

Create new version for crates.io

For some time now, the version of rink on crates.io has been failing to build on many of my machines due to a problem with OpenSSL. However, I just noticed that master builds fine on my machines (possibly due to 0db3f4d).

It would be much appreciated if a new version would be pushed to crates.io, so that I can delete the debian stable docker container I currently use for rink ;).

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.