Giter Site home page Giter Site logo

bobgneu / human-format-rs Goto Github PK

View Code? Open in Web Editor NEW
19.0 19.0 8.0 63 KB

Rust Port of human-format from node, formatting numbers for us, while the machines are still at bay

Home Page: https://bobgneu.github.io/human-format-rs/

License: MIT License

Rust 100.00%
formatter numbers rust

human-format-rs's Introduction

๐Ÿ‘‹ Hi, Iโ€™m @BobGneu

Iโ€™m interested in solving technical riddles across many domains. Iโ€™m currently learning about Rust, CPP, & Typescript.

Iโ€™m looking to collaborate on games, robotics, testing, misc. developer tooling.

I'm best reached through email or on Discord.

I have worked on

  • Games & Game Engines
  • Robotics
  • Video Streaming
  • Architecture & Design of cloud systems
  • Tools & Plugins for various platforms
  • General Automation & Web Scraping

I enjoy the absolute crap out of performance optimization in the software space.

human-format-rs's People

Contributors

bobgneu avatar dabreegster avatar jaysonsantos avatar jgrund avatar mbrobbel avatar utopiabound avatar

Stargazers

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

Watchers

 avatar  avatar  avatar

human-format-rs's Issues

Crashes with large numbers

E.g. 1.2123123422324232e16

... panicked at 'attempt to multiply with overflow', /rustc/e85edd9a844b523a02dbd89f3c02cd13e4c9fe46/library/core/src/num/mod.rs:843:5
stack backtrace:
   0: rust_begin_unwind
             at /rustc/e85edd9a844b523a02dbd89f3c02cd13e4c9fe46/library/std/src/panicking.rs:584:5
   1: core::panicking::panic_fmt
             at /rustc/e85edd9a844b523a02dbd89f3c02cd13e4c9fe46/library/core/src/panicking.rs:142:14
   2: core::panicking::panic
             at /rustc/e85edd9a844b523a02dbd89f3c02cd13e4c9fe46/library/core/src/panicking.rs:48:5
   3: core::num::<impl u32>::pow
             at /rustc/e85edd9a844b523a02dbd89f3c02cd13e4c9fe46/library/core/src/num/uint_macros.rs:1952:24
   4: human_format::Scales::to_scaled_value
             at /Users/ivanschuetz/.cargo/registry/src/github.com-1ecc6299db9ec823/human_format-1.0.3/src/lib.rs:236:29
   5: human_format::Formatter::format
             at /Users/ivanschuetz/.cargo/registry/src/github.com-1ecc6299db9ec823/human_format-1.0.3/src/lib.rs:121:28

Version 1.0.3

Support for time units

Would be possible to support non-uniform scales such as day/hour/minute/second/millisecond/microsecond/... ?

Support for milli, micro etc?

It would be nice if the smaller SI prefixes were supported as well. milli, micro, etc.
I guess that requires changing the API though. Either changing the meaning of Scales::suffixes or adding a second vector for the other standard eight/ten prefixes (with or without deci-/centi- prefixes).

The binary base should be 1024

Scales::Binary seem to define the wrong base. A kibibyte is 1024 bytes, not 1000 as is in the code. It should also be shortened to KiB, not kiB.

Scales::SI does not use the correct suffix for the billion

Summary of Issue or Feature

Currently the Scales::SI is not using the correct SI suffix for the billion:
it is using B instead of G

Logs & Source Code

Current code (v1.0.3):

    pub fn SI() -> Self {
        Scales {
            base: 1000,
            suffixes: vec![
                "".to_owned(),
                "k".to_owned(),
                "M".to_owned(),
                "B".to_owned(),
                "T".to_owned(),
                "P".to_owned(),
                "E".to_owned(),
                "Z".to_owned(),
                "Y".to_owned(),
            ],
        }
    }

Expected code:

    pub fn SI() -> Self {
        Scales {
            base: 1000,
            suffixes: vec![
                "".to_owned(),
                "k".to_owned(),
                "M".to_owned(),
                "G".to_owned(),
                "T".to_owned(),
                "P".to_owned(),
                "E".to_owned(),
                "Z".to_owned(),
                "Y".to_owned(),
            ],
        }
    }

image
https://en.wikipedia.org/wiki/International_System_of_Units#Prefixes

image
https://www.nist.gov/pml/weights-and-measures/metric-si-prefixes

SI units for 1e9 are wrong

Summary of Issue or Feature

SI units for 1e9 are listed with suffix "B" but it should be "G" as that's the SI for 1e9. https://mathworld.wolfram.com/SIPrefixes.html

The intention is clearly to support "billion" for human friendly, but I think that should have a different set of suffixes, especially since it's technically not even localized properly (e.g. North America uses B but UK uses bn). I think there needs to be a Scales::ABBREVIATED_NORTH_AMERICA() for the B billion suffix instead.

Reproduction Steps

human_format::Formatter::new().with_suffixes(human_format::Scales::SI()).with_units("B/s").format(1e9);

Expected: 1 GB/s
Actual: 1 BB/s

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.