For questions with concerns specifically related to the usage of floating point, such as accuracy and precision of calculations, handling of 0, infinity, and over/underflow, input/output, and binary representation. Not for code that casually happens to use floating point.

learn more… | top users | synonyms (1)

-1
votes
0answers
26 views

Feedback on float getter [closed]

I have never worked with floats and I need your feedback on my function: https://github.com/Ostefanini/get_float.git
-3
votes
1answer
52 views

Printing a prime normalized sequence

The program below generates a prime normalised sequence. So, what happens is this: It asks you to provide a number within a range. Program then calculates a factor which is inverse of product of all ...
2
votes
0answers
36 views

Numerical differentiation using the y-intercept

I have a routine for determining the derivative of a function using the y-intercept (B) to infer the finite difference step (h). ...
1
vote
3answers
40 views

Byte array to floating point such as FPE2 in Java

Apple's System Management Controller uses FPE2 and SP78 as floating-point formats. While writing a Java library that that interfaces with the SMC, I ported someone's C function to convert read a ...
-2
votes
0answers
41 views

Count decimal places of pi number

My program asks how many decimal places of pi number do want to see. I would like to ask for your review about my code. I have also two questions: Why I had to add 1 (getcontext().prec = places+1) ...
3
votes
2answers
58 views

Function that strips trailing '0's from a float

I'm writing an embedded application in C, and at one point I need to convert a float into an ASCII representation of that float, so I can send the ASCII over a serial port. The protocol the serial ...
6
votes
1answer
122 views

Generic and accurate floating point “equality”

Like those who have come before me, I foolishly have sought to implement a generic, efficient, idiomatic, and most importantly correct method of comparing floating point numbers for equality. Like ...
4
votes
2answers
108 views

Calculating the equivalent value of 2 resistors or capacitors

I started learning C# and this is my first "project". Its main purpose is to calculate the equivalent value of two resistors or capacitors connected in either series or parallel. I just finished it ...
1
vote
1answer
59 views

Program to count number of victories in a pool of contests

I changed the program to use a dynamic array instead of a vector or storing the integers. This program works without bugs and executes relatively fast. The only doubt Istill have is how to fill the ...
3
votes
2answers
64 views

Decimal-to-fraction solver

I have created a program that turns a decimal into a fraction: ...
3
votes
1answer
57 views

Portably generate uniformly random floats from mt19937 output

My goal is to generate a sequence of random float from a seeded random generator. The sequence should be the same on any machine / any compiler -- this rules out ...
3
votes
1answer
56 views

Workaround for the precision limitation for Python's round() function

I'm trying to come up with a general way to correctly round floats with Python, given the known limitation of round(): Note: The behavior of ...
4
votes
0answers
123 views

Linear Interpolation C++

I have to write a collection of methods for performing linear, bilinear and trilinear interpolation. I have also to write some tests to show that interpolation is exact for polynomials (which should ...
5
votes
4answers
918 views

`atof` implementation

I have implemented the atof function. Here is my implementation ...
4
votes
1answer
77 views

Preventing numbers from showing up in scientific notation

We have a StreamBuffer class which is not inherited from std::ios_base (or some of it's derivatives such as ...
0
votes
1answer
40 views

Creating indexes from a theoretical decimal/int, splitting into before and after arrays

I'm currently populating before and after arrays with indexes, based on a number provided. If the input going in is an int, ...
3
votes
1answer
43 views

“The Trip” expense-equalizing challenge [closed]

I've solved The trip from Programming Challenges. My solution suffers from lack of floating-point precision, though. The problem: Your job is to compute, from a list of expenses, the minimum ...
3
votes
0answers
36 views

Extension of PHP `round()` for PHP_ROUND_UP and PHP_ROUND_DOWN - follow-up

The original question can be found here. While looking at PHP.net this afternoon, I saw a comment in round() for two functions for rounding ...
1
vote
1answer
44 views

Extension of PHP `round()` for PHP_ROUND_UP and PHP_ROUND_DOWN

While looking at PHP.net this afternoon, I saw a comment in round() for two functions for rounding UP and ...
1
vote
1answer
44 views

Span decimal point precision

In a JSP page I have a number of Span elements. Each of this span element will be floating point numbers. All these span elements has class ...
10
votes
3answers
90 views

Reinventing the Math Functions

Just for practice in the mathematical side of programming, I decided to rewrite the math functions, with the addition of the root() function, which the Math library ...
14
votes
5answers
2k views

One program using three functions to compare two double-precision numbers

I am currently learning C++ though Bjarne Stroustrup book Programming Principles and Practices using C++. Going through the drills, I am trying to purposefully write efficient and readable code (good ...
2
votes
1answer
50 views

Create a rotation matrix [closed]

I adapted this piece of code from a math book for game developers and the result is correct albeit with slight floating point errors. ...
3
votes
2answers
290 views

Float to Byte Array Serialization Over Network

I wrote this code for a multiplayer game I am developing to transmit floats over the network. It works, on the systems that I have tested it with. What I am worried about is the little-endian ...
3
votes
1answer
97 views

Finding nearest float values corresponding to a data point (of three variables) in a table with multiple columns using C++

I have a data file which contains floating point data arranged in 4 columns. Each row represent a specific data point. The first column(X) is made up of 100 different values but the values are ...
4
votes
1answer
86 views

Movement code for a game that should be able to handle almost infinite coordinates

Now I've grasped the very basics of Pygame, I thought it'd be useful to make a few classes that I could use later on if I try make a simple RPG style game. I've done this to handle the coordinates for ...
4
votes
3answers
1k views
2
votes
1answer
113 views

A Scala script for beautify scientific notation strings from Excel

Excel renders scientific notation in the engineering fashion, e.g. “4.2E-5”. That’s OK, but when you are writing a scientific paper, it’s likely that you want it to look like this: “4.2×10⁻⁵”. I have ...
8
votes
3answers
331 views

Floating point equality in Java - follow-up

This is a follow up post for this question. There aren't a lot of changes. The changes (all of them major) are: I've decided to ditch my previous approach using ...
21
votes
4answers
842 views

Floating point equality in “Numbers.java”

Floating point inaccuracies are really annoying. I understood that in its true sense while developing the next version of Point (this time I'm actually foolproofing my code). Before I upload it for ...
4
votes
1answer
87 views

Signum function

This is the Java signum(double) method I am trying to imitate: ...
5
votes
1answer
171 views

A Range object for Java that partially implements `List`

I'm writing a neural net which uses a genetic algorithm to adjust the weights. To represent the possible range of "genes" for the GA, I'm passing in a list of bases. Unfortunately, I realized after ...
4
votes
2answers
105 views

Get an integer as input and display Pi rounded to that amount of decimal places

I've been writing a program that accepts an integer as input and displays the number Pi rounded to that number. The only issue I see is the fact that the Math.Round ...
3
votes
1answer
54 views

Right-justifying a number with dot leaders

I'm working on a small library to help me format numbers easier as my current project deals with a lot of them. I want to be able to just supply the value, precision, width, and fillchar to a method ...
4
votes
1answer
68 views

Check if a String is a valid Double

For a class, I need to ask the user for a double. To verify that the number can be safely passed to Double.parseDouble, I wrote ...
5
votes
1answer
254 views

JavaScript 8-bit floating point

To start, I am in the wrong language and I think it is time learn some C++ and compile it as an add-on for NodeJS. For now, though, I have a few code snippets that work that may be interesting or may ...
10
votes
3answers
146 views

Distance between two n-dimensional points (NASM)

I just finished writing a function that computes the distance between two n-dimensional points. The original one was written in C and it's basically a translation of this formula: ...
2
votes
3answers
3k views

Converting a double to a std::string without scientific notation

Problem I need to convert a double to a std::string which contains no scientific notation and no unnecessary fillers. Using ...
6
votes
4answers
126 views

Build a double from a stream of chars

Back in my calculator post, janos suggested I either find a better way to read a double from a StreamReader or else go the whole ...
4
votes
2answers
171 views

Converting a number to binary and back as a test in Java

This is one of my first takes on Java, coming mainly from Matlab I found I had many things to learn. The code will try to convert a number into an array of ones and zeros and then do the opposite ...
4
votes
2answers
179 views

Storing currency-precision values

I'm trying to develop a program that stores currency values. In my particular application I only care about two decimal of precision (cents) but have read it's a good idea (for accuracy when dealing ...
4
votes
2answers
247 views

Java helper function to round a number to the specified number of decimal places

The function I need: Rounds a double to the specified number of decimal places I figured this would be a part of java.lang.math, but inexplicably it doesn't ...
5
votes
4answers
2k views

Compare two doubles to N decimal places

I have a function that compares two doubles to N decimal places. ...
4
votes
2answers
1k views

Square Root Calculator

I have now written a simple square root calculator using the division method: ...
8
votes
3answers
285 views

Computing the relative magnitude of the values in one double array to another

An interview question I received: You are given two unsorted lists of positive doubles x contains the results from experiment 1 ...
19
votes
8answers
2k views

Optimize custom double.parse()

In my company's code, they use double.tryParse() which is quite good but sets too much security for our needs. As we sometimes have to parse a few billion strings, ...
1
vote
2answers
172 views

“Rational” Wrapper class with support for Rational Number Approximation

Enough with imprecise floating point datatypes called float anddouble. I present to you Rational. Of course, Rational number ...
11
votes
2answers
737 views

Foolproof number validation

I know there have been a lot of post, blog article answer on Stack Overflow (but the validation does return true on a tab character) about this. But I'm still ...
10
votes
4answers
1k views

Computing the square root of a 64-bit integer

When sieving primes up to some 64-bit number n I need to determine an upper bound for the greatest potential factor of n, which ...
8
votes
2answers
311 views

Parsing integers safely

Background I'm writing user input validation for a client-side JavaScript web application. Users enter numerals representing an integer into an <input>. As ...