nowfound

Life & fun · October 18, 2024

Floating point arithmetic types in C++ for any size and any base

Since there is so much interest on HN in floats lately and their software implementations, I wanted to show mine. It has no use and is just for teaching me floats and C++. Give me your thoughts.

Floating point arithmetic types in C++ for any size and any base launched on October 18, 2024 with 79 votes, #597 of 5,185 launches that month and more than 90% of that year's launches. The site was still online in September 2026, 2 years on.

Visit github.com ↗Alternativestop 12% of October 2024

In plain words

This is a C++ library implementing floating point arithmetic types that support arbitrary sizes and number bases. It was created as a learning project to explore how floating point numbers work and to develop C++ skills. The project is educational in nature with no practical applications, hosted on GitHub for review and feedback from the programming community.

written from the facts on this page · September 2026

From the sources

A floating point arithmetic which works with types of any mantissa, exponent or base in modern header-only C++. - clemensmanert/fas

fas is floating point arithmetic for arbitrary mantissa and exponent types in modern header-only C++ . It lets you construct various different float types using template parameters for the mantissa, exponent and base. The constructed float-types look and fell like a native float/double for arithmetic operations. Furthermore all methods are performed on the stack and do not require any heap space. fas::Float< int16_t , int8_t > f; This will result in a float using a signed 16 bit mantissa and a signed 8 bit exponent. fas::Float< int16_t , int8_t > f1 = 10 ; auto f2 = f1; f2 = -f1; // => -10 f2 = f1 + 10 ; // => 20 f2 = f1 - f1; // => 0 f2 = f1 * f1; // => 100 f2 = f1 / 20 ; // => 0.5 f2 += 1…from github.com

Does a similar job

all alternatives →
  • Kotlin Money2024 · blog.eriksen.com.br · ▲427

    Manipulating monetary amounts is a common computing chore. However, no mainstream language has a first-class data type for representing money, it’s up to programmers to code abstractions for it. This isn’t an issue per se until dealing with rounding issues from operations like installment payments (e.g., buy now, pay later), foreign exchange, or even simple things like fee processing and tax collection. Inspired by my days at N26 Brasil dealing with these challenges, I introduce Money: a Kotlin library that makes monetary calculations and allocations easy.

  • Sum (algebraic) types for C in one 100 line header2024 · github.com · ▲92

    A mirror of https://git.sr.ht/~grego/sumtypes.h. Contribute to grego/sumtype.h development by creating an account on GitHub.

  • Fast Random Library for C++172025 · github.com · ▲52

    Morning HN. Random number generation feels is a somewhat underrepresented topic in the C++ realm. There is a lot of questionable info about it found online and even the standard library is quite behind the times in terms of it's algorithms. It suffers from trying to accommodate sometimes impractical standard requirements and has several ways of getting significantly bad statistical results. This leaves a lot easily achievable performance & quality on the table. So, being a mathematician who mostly works with stochastic models and wants these models to run fast and well, I embarked on a…

  • dnum − A small TypeScript library to handle decimal numbers2023 · github.com · ▲42

    🧮 Small library for big decimal numbers. Contribute to bpierre/dnum development by creating an account on GitHub.

  • HT
    How to program in Rust as if it was old school C++ with pointers2022 · ▲24

    Basically wrap your data struct in Option>> Better yet, use your custom type that provides few helper functions that make using it as nice as old C++ pointers. Obviously there's no pointer arithmetic, but it works great for dynamically allocated structures like trees or linked lists. Please comment how it's a horrible idea that will bring doom to me and my family. fn main() { struct Data { pub number: i32 } &#x2F;&#x2F; struct Data { int number; }; let mut p:Pointer = Pointer(None); &#x2F;&#x2F; Data *p = NULL; println!("{}", p.is_none()); &#x2F;&#x2F; printf(p == NULL ? "true\n" :…

  • Build your own programming language in C++2021 · github.com · ▲94

    A minimal viable programming language on top of liblgpp - codr7/alang

More life & fun this month

the category →

Source: Show HN post ↗

Launched alongside, October 2024

the whole month →
  • buzzabout▲1,267

    Audience insights from 1B+ online discussions in 2 mins

    AI · 2024 · buzzabout.ai

  • bolt.new▲1,230

    Build and scale high-performing websites & apps using your words. Join millions and start building today.

    AI · 2024 · bolt.new

  • Feta▲1,217

    Run smarter stand-ups, build better products

    AI · 2024 · feta.io

  • Trag▲955

    AI code review companion

    AI · 2024 · usetrag.com

  • Turn Notion databases into portals & apps with no code

    Dev tools · 2024 · softr.io

  • One inbox for all your work discussions

    Work · 2024 · generalcollaboration.com