The Stack Overflow podcast is back! Listen to an interview with our new CEO.

Questions tagged [floating-point]

Approximate representation of numbers as a fixed number of digits multiplied by a logarithmic scale.

Filter by
Sorted by
Tagged with
19
votes
7answers
7k views

Why floating point representation uses a sign bit instead of 2's complement to indicate negative numbers

Consider a fixed point representation which can be regarded as a degenerate case of a floating number. It is entirely possible to use 2's complement for negative numbers. But why is a sign bit ...
15
votes
4answers
2k views

Inequality caused by float inaccuracy

At least in Java, if I write this code: float a = 1000.0F; float b = 0.00004F; float c = a + b + b; float d = b + b + a; boolean e = c == d; the value of $e$ ...
13
votes
1answer
405 views

Floating point rounding

Can an IEEE-754 floating point number < 1 (i.e. generated with a random number generator which generates a number >= 0.0 and < 1.0) ever be multiplied by some integer (in floating point form) to ...
10
votes
9answers
3k views

Represent a real number without loss of precision

Current floating point (ANSI C float, double) allow to represent an approximation of a real number. Is there any way to represent real numbers without errors? Here's an idea I had, which is anything ...
10
votes
1answer
582 views

Implementation of Naive Bayes

I am implementing a Naive Bayes algorithm for text categorization with Laplacian smoothing. The problem I am having is that the probability approaches zero because I am multiplying many small ...
9
votes
1answer
243 views

Why does floating point modulus exactness matters?

Most Smalltalk dialects currently implement a naive inexact floating modulus (fmod/remainder). I just changed this to improve Squeak/Pharo and eventually other Smalltalk adherence to standards (IEEE ...
7
votes
5answers
953 views

Number of FLOPs (floating point operations) for exponentiation

What is the number of floating point operations needed to perform exponentiation (power of)? Assuming multiplication of two floats use one FLOP, the number of operations for $x^n$ will be $n-1$. ...
7
votes
1answer
132 views

Difference between ways to compare floating-point numbers

There seems to be many approaches to judge whether two floating-point numbers are identical. Here are some examples I've found: ...
6
votes
2answers
308 views

What is the reason of inaccuracy of operations on float numbers?

I wonder why in JavaScript 0.1 + 0.2 // return 0.30000000000000004 4%0.1 // return 0.09999999999999978 http://jsbin.com/oHISAfU/1/edit (Example) In C the ...
6
votes
2answers
92 views

Program transformations for numeric stability

There's tons of research on program transformations for optimization. Is there any research on transformations that improve numeric stability? Examples of such transformations might include: ...
6
votes
1answer
465 views

Simple algorithm for IEEE-754 division on 8-bit CPU?

IEEE Std 754-2008 is the modern definition of Floating-Point Arithmetic. It requires that division (among other operations) performs as if it first produced an intermediate result correct to ...
5
votes
1answer
2k views

Confused by Floating Point Spacing

I'm currently taking a numerical analysis class in college and we're covering floating point systems. For the most part, I have a good grasp on it. However, something I can't seem to visualize, and ...
5
votes
0answers
97 views

What is the state of the algorithmic art for floating point arithmetic on complex numbers?

Most modern compilers and processors implement the IEEE 754 binary formats for floating point numbers. IEEE 754 guarantees that the addition, subtraction, multiplication, division, and square root ...
4
votes
2answers
171 views

Proof that (x-y)(x+y) is more accurate than x²-y²

I was carrying on my reading of What Every Computer Scientist Should Know About Floating-Point Arithmetic but got stuck on the proof of Theorem 2 (page 34). At some point it says: \begin{align} (x \...
4
votes
1answer
93 views

Imaginary numbers and negative zero

I've been studying the low-level hardware implementations of floating point numbers and doing an exercise to design a custom floating point implementation. I know that being able to represent ...
4
votes
2answers
60 views

Union of fixed and floating point types

Say I have two real number types. They may be floating or fixed point. How can I construct a new type whose values are at least the union of the two with the minimal number of bits? There are 3 cases ...
3
votes
2answers
3k views

What does normalizing with hidden bit really mean?

I have a question related to representing numbers in base 2 with floating point. For example, if I have such a number $$0.000011 \cdot 2^3$$ then is its normalized form this? $$1.1\cdot 2^{-2}$$ ...
3
votes
1answer
225 views

Can we improve the precision of IEEE floats by dropping leading zeros in the mantissa?

It seems like it would be possible to add more precision to the IEEE 32-bit mantissa system if the leading zeroes were also dropped, just like the leading 1 is dropped due to it being implicitly known....
3
votes
1answer
122 views

When does the IEEE-754 64-bit float break as a counter

As a matter of curiosity I've been trying to determine at what point a 64-bit float no longer reflects the addition of 1 as expected; that is, at what point the digits as printed do not correspond to ...
3
votes
2answers
864 views

Is the exponent in floating point numbers signed or unsigned

This may be sound like a stupid question, because, of course, it can be negative and, as Wikipedia states: A numeric variable is signed if it can represent both positive and negative numbers, and ...
3
votes
1answer
239 views

Is < binary relation a strict partial order on IEEE doubles?

To me it looks that it is: irreflexivity: NaN < NaN == false transitivity: if a < b and b < c then a < c (the antecedent is never true for NaNs) asymmetry: if a < b then not b < a (...
3
votes
1answer
262 views

Is “flops” a reliable measure of deciding computational capacity?

Is "flops" a reliable measure of deciding computational capacity? If we do matrix multiplication and matrix addition of the same size of matrix, do the flops remain the same? Referring to question ...
3
votes
2answers
100 views

Floating point format: why must `1−emax ≤ q+p−1 ≤ emax`?

From the Wikipedia page on the IEEE Standard for Floating-Point Arithmetic, The possible finite values that can be represented in a format are determined by the base (b), the number of digits in ...
3
votes
2answers
97 views

How much can we trust mathematical software when working with large numbers, and how much memory it needs to work with these numbers?

For example, I want to evaluate the expression: $3^{3^{{3}^{3}}}$ so I used wolframalpha.com (it's free, and I don't own any software), which returned the scientific notation of the number above, ...
3
votes
1answer
56 views

Why do I get really different results with my benchmarking code I made?

I'm doing research work for my last year in high school. My work is about processors and for the experimental part i've coded an app that can mesure how many Floating Point Operation can a processor ...
3
votes
1answer
436 views

Why do floating point values have infinity?

Why do floating point values have infinity instead of just a higher exponent?
3
votes
1answer
242 views

Why a separate ALU is needed, since any integer can be represented as floating point numbers?

Most of the operations in computer are using floating point arithmetic.Put it simply why a Floating Point Unit alone is not sufficient? Can we do away with ALU?Is FP operations are resource intensive ...
3
votes
3answers
557 views

Whether assigning of single precision IEEE754 float to double is reversible?

Using the IEEE754 standard, let's assign single precision variable s to double precision variable d and then assign d to single precision variable s'. Is this operation is reversible (lossless) for ...
3
votes
1answer
1k views

Smallest number close to 0 in IEEE754 (64bits)?

I thought the smallest number close to 0 would be : 0 00000000001 (exponent) 0000000000000000000000000000000000000000000000000000 (significand) But this site (http://binaryconvert.com/result_double....
3
votes
3answers
63 views

Guarantees on computing $a+x(b-a)$ in floating point

I want to implement the function $f(x,a,b) = a + x(b-a)$ where all the inputs are floating point (doubles, say), such that (a) $f(0,a,b)=a$ exactly; (b) $f(1,a,b)=b$ exactly; (c) $f(x,a,b) \le f(y,a,b)...
3
votes
1answer
43 views

Formal notations of equivalencence between floating point expressions

In an informal context, most programmers might call these two expressions "equal" and no one would be mislead: (a + b) + c a + (b + c) For floating point numbers,...
3
votes
2answers
1k views

How to prevent overflow and underflow in the Euclidean distance and Mahalanobis distance

I was working in my project when I was struck by the question of whether it would be necessary, or at least cautious, prevent overflow and underflow in the calculation of these two distances. I ...
3
votes
1answer
93 views

Understanding truncation and rounding error in IEEE floating point system?

I'm trying to understand the theory behind finding the optimal $h$ value for differentiation in this definition: $$ \frac{f(x+h) - f(x)}{h}$$ as $h$ tends to 0. Here is my understanding: ...
3
votes
1answer
17k views

Normalizing the mantissa in floating point representation

How to represent $0.148 * 2^{14}$ in normalized floating point arithmetic with the format 1 - Sign bit 7 - Exponent in Excess-64 form 8 - Mantissa $(0.148)_{10} =...
3
votes
0answers
89 views

Representing Computations on Transcendental Numbers

Consider the set of transcendental numbers that are not compressible to a finite base-2 representation. How can I compute multiples (more generally, any algebraic computation) of one of these numbers,...
2
votes
2answers
197 views

What's the algorithm for floating points equality test?

I've found that 0.1 + 0.2 == 0.3 is not true in Java (see this demo). So, I'm interested in how equality testing can be implemented for floats. Is there a ...
2
votes
3answers
3k views

Floating point normalised numbers in binary

Many text books state that for a binary floating point representation in a computer byte, that if the mantissa is normalised, then a positive number must start with 01 from the left or a negative ...
2
votes
2answers
215 views

Gap between numbers in fixed-point vs. floating point arithmetic

If $r$ is a machine-representable number and $f(r)$ is the next larger machine representable number, are the following true or false? In fixed-point arithmetic, the distance between $r$ and $f(r)$ is ...
2
votes
1answer
73 views

Floating point arithmetic

I need to change x1 = 0.3 and x2 = -0.29 to a FP(floating point) number with one sign bit, a 4 bit mantissa, a 3 bit exponent. The results I got are: x1: 0 001 0011 x2: 1 001 0010 I am also trying ...
2
votes
1answer
484 views

Will floating point code return the same arithmetical results on two different computers?

Say I am using boost or the built-in float or double mathematical libraries of my C++ compiler. I distribute the program. Will the execution of my C++ program on different machines given different ...
2
votes
2answers
809 views

Floating Point Systems - Rounding Error in Taylor series

I have a question about rounding error. I have created a function to approximate exp(x) by summing the terms of its taylor series until the sum stops changing. (That is, 1 + x + x^2/2! ...). This ...
2
votes
2answers
30 views

Why multiplying float number by multiple of 10 seems to preserve better precision?

It is famous that for float numbers: .1 + .2 != .3 but 1+2=3 It seems that multiplying floats by 10 allows you to preserve ...
2
votes
2answers
390 views

Find the duplicates in a list of floating point numbers

I receive a list of real numbers ( float ) between $0$ and $1$. The list has length $N+1$ and I need to find two numbers on the list which are $\le \frac{1}{N}$ ...
2
votes
1answer
132 views

Approximate a float using a minimal fraction

This sounds like it's probably a well-known problem, but I haven't been able to find references to it by searching. Given a floating point value $x$ and an error range $\varepsilon$, how can I ...
2
votes
1answer
1k views

Calculating Binet's formula for Fibonacci numbers with arbitrary precision

Binet's formula for the nth Fibonacci numbers is remarkable because the equation "converts" via a few arithmetic operations an irrational number $\phi$ into an integer sequence. However, using finite ...
2
votes
1answer
52 views

numerically stable log1pexp calculation

What are good approximations for computing log1pexp for single precision and double precision floating point numbers? Note: ...
2
votes
1answer
540 views

Distribution of IEEE 754 single precision floating point over number line

"What is the maximum and minimum difference between two successive real numbers representable in IEEE 754 Single Precision and Double Precision Floating Point Representations respectively?" In ...
2
votes
1answer
6k views

Hex Bit Pattern to IEEE 754 standard Floating Point Number

The question asks for the decimal number that 0x0C000000 represents if it is a floating number. I'm not too sure on how to approach this, but here's my thought process: 0x0C000000 = 0000 1100 0000 ...
2
votes
2answers
2k views

Controlling overflow and loss of precision during floating point multiplication

I have a large number of floating point numbers (~10,000 numbers) , each having 6 digits after decimal. Now, the multiplication of all these numbers would yield about 60,000 digits. But the double ...
2
votes
2answers
1k views

How to estimate floating-point precision of function?

Let's say I have a function that consists solely of floating-point operations where the last operation rounds the computed value to a predefined number of digits. And I feed this function with a range ...