Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is this feature of floating point?

Tags:

d

point

floating

Real Close to the Machine: Floating Point in D

https://dlang.org/articles/d-floating-point.html

says

Useful relations for a floating point type F, where x and y are of type F

...

  • x>0 if and only if 1/(1/x) > 0; x<0 if and only if 1/(1/x) < 0.

what is the meaning of this sentence?

like image 980
yohabe Avatar asked May 21 '18 13:05

yohabe


People also ask

What is the use of floating-point?

Floating point numbers are used to represent noninteger fractional numbers and are used in most engineering and technical calculations, for example, 3.256, 2.1, and 0.0036. The most commonly used floating point standard is the IEEE standard.

What is meant by a floating-point?

A floating point number, is a positive or negative whole number with a decimal point. For example, 5.5, 0.25, and -103.342 are all floating point numbers, while 91, and 0 are not. Floating point numbers get their name from the way the decimal point can "float" to any position necessary.

What are the 2 types of floating-point?

There are two floating point primitive types. Data type float is sometimes called "single-precision floating point". Data type double has twice as many bits and is sometimes called "double-precision floating point".


1 Answers

In the text you're quoting, we're looking at how the representation is symmetric around 1, and that the rounding doesn't break this. That is, for any number 0 < x < 1, there's a corresponding number 1 < y < ∞, such that y = 1/x and 1/y = x. That's the first half - the second is simply the same for negative numbers: 0 > x > -1 and -1 > y > -∞.

It may not be immediately obvious how this can be a problem, but consider x = 3. y must then be 1/3 = 0.333.... With a limited precision of 3 decimal digits, 1/y would then be 3.003003003.... IEEE 754 defines how this should work, and says that the rounding should ensure 1/(1/x) should be equal to x, and thus that the result should be 3, even if there are rounding errors in both 1/x and 1/y - they should cancel each other out.

Older floating-point systems weren't as well-behaved as IEEE 754. I'm not sure if any of them weren't symmetric around 1, but that's certainly within the realm of possibility.

like image 51
BioTronic Avatar answered Oct 21 '22 19:10

BioTronic