Avoid Overflow when Calculating π by Evaluating a Series Using 16-bit Arithmetic?

Take a look at related QA: Baking-Pi Challenge – Understanding & Improving Its using Wiki: Bailey–Borwein–Plouffe_formula which is more suited for integer arithmetics. The real challenge however would be: How do I convert a very long binary number to decimal?. As you probably want to print the number in dec base … Also if you … Read more

Fast fixed point pow, log, exp and sqrt

A very simple solution is to use a decent table-driven approximation. You don’t actually need a lot of data if you reduce your inputs correctly. exp(a)==exp(a/2)*exp(a/2), which means you really only need to calculate exp(x) for 1 < x < 2. Over that range, a runga-kutta approximation would give reasonable results with ~16 entries IIRC. … Read more

Fixed point math in C#

Ok, here’s what I’ve come up with for a fixed-point struct, based on the link in my original question but also including some fixes to how it was handling division and multiplication, and added logic for modules, comparisons, shifts, etc: public struct FInt { public long RawValue; public const int SHIFT_AMOUNT = 12; //12 is … Read more

What’s the best way to do fixed-point math? [closed]

You can try my fixed point class (Latest available @ https://github.com/eteran/cpp-utilities) // From: https://github.com/eteran/cpp-utilities/edit/master/Fixed.h // See also: http://stackoverflow.com/questions/79677/whats-the-best-way-to-do-fixed-point-math /* * The MIT License (MIT) * * Copyright (c) 2015 Evan Teran * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the … Read more

Fixed Point Arithmetic in C Programming

The idea behind fixed-point arithmetic is that you store the values multiplied by a certain amount, use the multiplied values for all calculus, and divide it by the same amount when you want the result. The purpose of this technique is to use integer arithmetic (int, long…) while being able to represent fractions. The usual … Read more