# Questions tagged [floating-point]

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.

175 questions
Filter by
Sorted by
Tagged with
45 views

### An IEEE half-float implementation in python similar to array.array, is there any way I could make this more efficient?

I've written this class to wrap a collection of bytes and interpret them as 16-bit floats. It's supposed to work like memoryview(buf).cast('f') or ...
75 views

### Safe runtime numeric casts

The rationale behind this code is to implement a runtime-safe number conversions in situations when precision loss is possible, but is not expected. Example: passing a ...
81 views

### Float to binary conversion

I wrote a program to convert float to it's binary IEEE754 representation in C. Any improvements to this is appreciated ...
43 views

### Locale-independent float print function

The objective was to write a locale-independent function that prints floating-point numbers (i.e. one that always uses . as a decimal point regardless of the locale)...
25 views

...
72 views

### Floating-point to String Conversion with Given Precision for Fractional Part

Faced with converting floating-point values from a sensor obtained to string on an embedded system to transmit over UART, I came up with the following dbl2str() to ...
130 views

### Accounting for floating point error when rounding

I have to implement some business logic that will round a number (typically a double) upwards. Given that this number comes from a third-party and I don't know how they come to calculate it I'm ...
91 views

### Pretty-print dollar amounts using custom precision for large amounts

Given a floating-point number, which is representing a dollar value, I'm aiming to return a rounded, human-readable string. Here are the rules for numbers equal to or greater than 1 million, equal to ...
441 views

### C# calculate total time worked with TimeSpan [closed]

So there is an existing codebase which calculates the total time worked per month. What the code is doing: iterates through all the working days entries retreives the value of net work time which is ...
401 views

### Plotting the integer values in text format in matplotlib piechart

I have done a clustering algorithm and represented the results in a pie chart as shown below. ...
51 views

### Suggestions on how to update equation?

After discovering Float Toy, my goal was to create my own version using Python and Tkinter. The results of the endeavor is shown below. Most of the functionality is complete, but the ...
74 views

### A program that reads 8763x2 values from a CSV file and initialises an array and few other variables

Relatively new to Python. Have some experience in C++. I have written a small program that reads a CSV file (SAMPLE) and initialises two arrays and few values. ...
81 views

### Function for comparing floating point numbers

I am trying to make a function for floating point numbers comparison. The goal is to "evaluate" all operators in single function: >, >=, =, <=, <. If X>Y, then F>0. If X==Y, F==0. If X<=Y, F&...
3k views

### IEEE 754 square root with Newton-Raphson

I have an implementation of the sqrt function that uses a combination of IEEE 754, packed bitfields, and the Newton-Raphson algorithm: ...
158 views

### Software floating-point multiplication

I wrote a floating-point multiplication function as an excercise. The program compares its result to the usual hardware multiplication result and for this purpose I use unspecified behavior, but the ...
142 views

### Union of two double arrays

I would like to merge two double arrays and remove from the result array approximately equal items. My two input arrays have ...
877 views

### Fixed-Size Floating-Point Types

I have created my own personal data structure libraries for C and I've re-engineered it about two times now and I've added alot of preprocessor checks and defines concerning OS type and compiler type. ...
330 views

### Python maintain precision for currency

Working with currencies I am aware it is not good to work with floating point values due to rounding and maintaining precision. Better is to work with integers. Would the following Currency class make ...
186 views

### Java Mandelbrot Set Viewer

I'm writing my own version of a Mandelbrot set generator, with pan and zoom functionality. (There's not yet a color overlay of sets generated with various beta values; the beta value is changed ...
668 views

246 views

### Round a number and replace trailing zeros by spaces

Goal From a number x, I would like a string of the rounded value at n decimals and replace each trailing zeros by a space. ...
98 views

### Checking whether a number starts with any of a list of string prefixes

This code will return false if the long double rand begins with any string in the vector ...
54 views

### error management when parsing multiple floats

I am writing a handler to render a GIF of a Lorentz attractor. I need to parse floating point numbers from the some querystrings attached to the GIF path. If any of them are bad, I need to log an ...
112 views

### Calculating Polynomial: Computing very large numbers emulating double using 2 floats

I am working on a polynomial algorithm which requires calculations in large numbers, up to e+38. I am using a 32-bit system with compiler support of 32 bits for long...
241 views

### Cloning Python standard library's function math.frexp() that extracts exponent and mantissa from a floating point number

This is Python 3.5 code. I have attempted to develop my own frexp() function that mimics the functionality of Python standard library's ...
535 views

### WGS84-coordinate encoded as Integers

I want to store WGS84-coordinates in two integers for latitude and longitude instead of floats to get a higher precision than with floats. Here's my code: ...