How is a floating point number represented in binary?

  • Thread starter zetafunction
  • Start date
In summary, the conversation discusses the idea of using only rational numbers in calculations instead of real numbers. It is mentioned that real numbers have nice properties and are important for theory, but it may be simpler to work with rational numbers in certain cases. However, approximating with rational numbers can introduce inaccuracies and decrease precision. It is also noted that working with rational numbers can be difficult in number theoretic calculations and it is often better to use reorganize the calculation to use only integers or to do the calculations in real numbers and then convert back to rational numbers. The conversation also addresses the assertion that all of trigonometry can be done with just rational numbers, but it is not considered a superior or accurate approach.
  • #1
zetafunction
391
0
the idea is, could we work only with a Q system of numbers ? i mean using only rational

the idea is that if we truncate the decimal expansion, almost any real number that appears in nature can be described by a rational number

example: [tex] 1.345353=1345353/1000000 [/tex]

so is there a real neccesity to introduce Real numbers ? at least when we deal with practical calculations, perhaps in many other cases is just simpler to work with Q instead just R
 
Mathematics news on Phys.org
  • #2
But almost all my favourite numbers are irrational =(
 
  • #3
zetafunction said:
so is there a real neccesity to introduce Real numbers ?

It's much easier to work with real numbers. They have nice properties like the supremum property. A great many problems have no solution over the rationals but have a solution over the reals.

Further, rational Diophantine equations are generally far harder than their real equivalents.

So it's less of 'have to' and more of 'want to'.
 
  • #4
I'm moving this to general math, because you're not discussing number theory.

I'm also going to run with your implicit assumption that we are considering an application where approximations are sufficient answers.


zetafunction said:
so is there a real neccesity to introduce Real numbers ?
Yes. They're obviously important for theory. They also improve accuracy -- if you approximate things with a rational number, you are introducing an inaccuracy, and need to decrease precision (sometimes by a signficant amount) to account for it.

See wikipedia's article on numerical stability.


perhaps in many other cases is just simpler to work with Q instead just R
No; you definitely want to work with R. The question is how to represent elements of R. Or, more correctly, how to represent intervals -- remember, if we're working with approximations, we have to keep track of how good those approximations are!

And floating-point notation is the most commonly used method for representing things.


Incidentally, even when you do really want to be working with Q, such as in number theoretic calculations, it is often much better to either:
(1) Go through great lengths to reorganize the calculation so that you use only integers
(2) Do the calculations in R (and/or in a p-adic field), then convert back to Q
 
  • #5
Quite a weak system if you cannot even have square roots, decent integrals, exponential functions, circle circumferences, trig functions... Yes for 5th grade math it is kind of useful, unless you start adding things like 99/100 + 99/101 and your representation starts exploding
 
  • #6
0xDEADBEEF said:
Quite a weak system if you cannot even have square roots, decent integrals, exponential functions, circle circumferences, trig functions... Yes for 5th grade math it is kind of useful, unless you start adding things like 99/100 + 99/101 and your representation starts exploding

Not necessarily. N.J. Wildberger asserts that all of trigonometry can be done with just rational numbers. His formulation is quite interesting.

By the way, why is your example sum in Q any worse than it would be in R?
 
  • #7
Hurkyl said:
I'm moving this to general math, because you're not discussing number theory.

I'm also going to run with your implicit assumption that we are considering an application where approximations are sufficient answers.



Yes. They're obviously important for theory. They also improve accuracy -- if you approximate things with a rational number, you are introducing an inaccuracy, and need to decrease precision (sometimes by a signficant amount) to account for it.

See wikipedia's article on numerical stability.



No; you definitely want to work with R. The question is how to represent elements of R. Or, more correctly, how to represent intervals -- remember, if we're working with approximations, we have to keep track of how good those approximations are!

And floating-point notation is the most commonly used method for representing things.


Incidentally, even when you do really want to be working with Q, such as in number theoretic calculations, it is often much better to either:
(1) Go through great lengths to reorganize the calculation so that you use only integers
(2) Do the calculations in R (and/or in a p-adic field), then convert back to Q

Hurkyl, I'm sorry I'm not following this. When do we ever not approximate things with rational numbers? Every instrument that I can think of measures in rationals, not reals. Floating point itself is rational, not real.
 
  • #8
Cantab Morgan said:
Hurkyl, I'm sorry I'm not following this. When do we ever not approximate things with rational numbers? Every instrument that I can think of measures in rationals, not reals. Floating point itself is rational, not real.
Suppose I asked you to solve x2=2 for x. Could you write down an exact solution using only the rationals?
 
  • #9
Cantab Morgan said:
Not necessarily. N.J. Wildberger asserts that all of trigonometry can be done with just rational numbers. His formulation is quite interesting.
A more commonly known way to do calculations with just rational numbers is to use vector calculus (e.g. dot products and cross products).

I've glanced at this before. After glancing again, his formulation still does not seem superior, and almost surely does not live up to his advertising. Of course, it's hard to give him fair consideration after he spends all that time making a mockery of trigonometry -- e.g. his claim that your calculator uses Taylor series to compute [itex]\sin x[/itex] is patently false.
 
  • #10
Cantab Morgan said:
Not necessarily. N.J. Wildberger asserts that all of trigonometry can be done with just rational numbers.

I though Pythagoras had disproved this a long time ago. I like to be able to take diagonals of a square.

His formulation is quite interesting.

By the way, why is your example sum in Q any worse than it would be in R?


The question is less the numbering system then the representation, all real numbers are approximated in calculation by sums of rational numbers (it called the decimal system)
But it seems you think it is better to work with the full numbers

99/100+99/101 = 19899/10100

If you add some more rational numbers to this, the denominator will grow until it contains all the prime powers that are present in the numerators. The denominator grows to be very large for negligible gains in accuracy. This is not pathological, it will happen when you approximate a series of something like an exponential function with the first terms.

Whereas the decimal notation has natural rounding build in:

99/100 + 99/101 [tex]\approx[/tex] .99+.98 = 1.97

And if you want some number of significant digits you know, when you can stop summing your series.
 
  • #11
Hootenanny said:
Suppose I asked you to solve x2=2 for x. Could you write down an exact solution using only the rationals?

No, of course not. But I cannot write down an exact solution at all. I can only write down an approximation of [itex]\sqrt 2[/itex], or even write down an algorithm that will converge to it.

0xDEADBEEF said:
I though Pythagoras had disproved this a long time ago. I like to be able to take diagonals of a square.

It only seems that way to you because you want to measure its length. And that's perfectly reasonable because length has a very desirable property: lengths add. But length isn't the only way you can compare the "heft" of line segments.

For example, you can construct squares whose sides are congruent to that diagonal segment you mentioned. And those squares will have areas, which are rational. Areas don't add in the same way that lengths do, which feels unnatural because we're so used to rulers. But taking areas as the "heft" of a line segment enjoys other interesting properties, some related to symmetries, besides being rational.

In any case, you can certainly construct the diagonal you mentioned.

0xDEADBEEF said:
The question is less the numbering system then the representation, all real numbers are approximated in calculation by sums of rational numbers (it called the decimal system)
But it seems you think it is better to work with the full numbers

99/100+99/101 = 19899/10100

If you add some more rational numbers to this, the denominator will grow until it contains all the prime powers that are present in the numerators. The denominator grows to be very large for negligible gains in accuracy. This is not pathological, it will happen when you approximate a series of something like an exponential function with the first terms.

Whereas the decimal notation has natural rounding build in:

99/100 + 99/101 [tex]\approx[/tex] .99+.98 = 1.97

And if you want some number of significant digits you know, when you can stop summing your series.

I'm not trying to be dense, but I'm still not following. Your decimal numbers .99 and .98 are not irrational. You seem to be suggesting that it's undesirable to work in rational numbers, and then offer an example using rational numbers to argue the point.
 
  • #12
Cantab Morgan said:
But I cannot write down an exact solution at all. I can only write down an approximation of [itex]\sqrt 2[/itex]
Um... you just did write down an exact solution.

even write down an algorithm that will converge to it.
That too is an exact solution.
 
Last edited:
  • #13
Hurkyl said:
A more commonly known way to do calculations with just rational numbers is to use vector calculus (e.g. dot products and cross products).

I've glanced at this before. After glancing again, his formulation still does not seem superior, and almost surely does not live up to his advertising. Of course, it's hard to give him fair consideration after he spends all that time making a mockery of trigonometry -- e.g. his claim that your calculator uses Taylor series to compute [itex]\sin x[/itex] is patently false.

Well, your calculator certainly could use Taylor series to compute sines, couldn't it? (Although I suppose most today use CORDIC or something more amenable to FPGAs.) But that's just a technological detail. It's still an approximation, relying on the converging nature of some or another algorithm.

I am loathe to use the word superior, but Wildberger's formulation is different in some interesting ways. For example, if we look at some of the (nearly) modern attempts to make Euclidean geometry more rigorous, things get complicated in a hurry. (At least for poor brains like mine.) Specifically, Hilbert's Axioms spend a lot of time getting "betweenness" right. And betweenness is a really important thing. If you don't get it right, then you wind up being able to "prove" false things like a Side-Side-Angle theorem for the congruence of triangles.

Wildberger's formulation is simpler when it comes to betweenness. For example, if I have points A, B, and C on a line, and I want to relate the lengths of the resulting segments, then the equation AB + BC = AC is only true if B is between A and C. If these collinear points fall in some other order, then that equation doesn't hold. However, under Wildberger's formulation, where length isn't central, the analogous relation among A, B, and C is completely symmetric. The same equation works no matter which point is in between the other two.
 
  • #14
Cantab Morgan said:
[...]
It only seems that way to you because you want to measure its length. And that's perfectly reasonable because length has a very desirable property: lengths add. But length isn't the only way you can compare the "heft" of line segments.

I don't want to compare line segments. I am a physicist I need irrational numbers all the time. When calculating the Voltage needed over a resistor for a certain power. When calculating the shortest path in some isolator, or the amplitude of the sinusoidal voltage function function after 1 second.

[/QUOTE]
[...]
In any case, you can certainly construct the diagonal you mentioned.
[/QUOTE]
No you cannot, I like my diagonals such that I can integrate along them using the minimal enclosing sigma algebra over the Borel measures.

I'm not trying to be dense, but I'm still not following. Your decimal numbers .99 and .98 are not irrational. You seem to be suggesting that it's undesirable to work in rational numbers, and then offer an example using rational numbers to argue the point.


False this was a second point not a support of the first one. Apart from the ugly incompleteness of the rational numbers, the clumsy trigonometry and the bad integration behavior there is a contradiction in your idea, and I thought you had noticed.

Everything we measure or write down as a decimal number can only be an approximation of a real number by a rational number. So if you are suggesting that this is what we should do, then your post is pointless, since that is what everyone does with calculators. As far as I see it there are two ways to make an argument:
1) Fraction notation has advantages
2) The mere concept of real numbers should be avoided.

So my first argument was against 2), and there are many more ever since we disproved Xeno. And my second was against 1), i.e. there are very undesirable properties of fraction notation, if you are dealing with approximations to real numbers.

If you want to do geometry on a grid, feel free maybe there are some uses, but especially in physics you start messing with the units by squaring, and this is very undesirable.
 
  • #15
Hurkyl said:
Cantab Morgan said:
But I cannot write down an exact solution at all. I can only write down an approximation of [itex]\sqrt 2[/itex]

Um... you just did write down an exact solution.

Heh heh. Did I? Or did I just write down the universally accepted shorthand notation for the equivalence class of all algorithms that converge to it? Oh, wait! That's what real numbers actually are. :smile:

Honestly, I don't think we are disagreeing. I think instead that I am just expressing myself poorly. I totally agree that reals are indispensable for theory and for many, many problems. But let me try to express myself better.

I'm coming at this discussion from the following perspective... At the end of the day, I need to know how many volts to dial up my machine to, or how many degrees I have to cool down my apparatus to. These, and all the numbers on all my gauges, are all rationals.

In the steps from setting my dials to reading my gauges, maybe there are times when I want to use irrationals, and some times where rationals will do fine all the way through. It depends on context.

Using symbolic representations for irrationals like [itex]\sqrt 2[/itex] are very desirable in some cases, because they can cancel out. If a human or a symbolic computer is doing some calculations, then perhaps some simplifications can be detected and exploited. The most stable calculation is the one you don't actually have to perform.

Alternatively, in a purely numerical calculation, I am (or rather my computer is) using rationals all the way through. All I'm suggesting is that this alternative case is a significant part of the work some scientists and engineers do.
 
  • #16
0xDEADBEEF said:
Everything we measure or write down as a decimal number can only be an approximation of a real number by a rational number. So if you are suggesting that this is what we should do, then your post is pointless, since that is what everyone does with calculators. As far as I see it there are two ways to make an argument:
1) Fraction notation has advantages
2) The mere concept of real numbers should be avoided.

So my first argument was against 2), and there are many more ever since we disproved Xeno. And my second was against 1), i.e. there are very undesirable properties of fraction notation, if you are dealing with approximations to real numbers.

Thank you, that really clears up where you are coming from, and now I understand much better.

I did not mean to suggest that fraction notation has compelling advantages. I'm sorry my language was poorly worded to lead you to infer that. I was using the term rational number to include decimal approximations of reals, and numbers representable numerically on a computer.

I really failed to express myself clearly on the other point. Sorry about that too! The concepts of real numbers are indispensable!

So I guess my post was pointless, but I don't think I would have used that term. :smile: I intended to respond in the spirit of the original poster's question about being simpler to do calculations numerically with rationals (but not keeping fractional notation). Perhaps the original poster meant keeping fractional notation, but I didn't interpret it that way when I read it.
 
  • #17
How is a floating point number represented in, say, 32 bits of mantissa?

I believe it's of the form, for example: (.101011001... / 2^32) * 2^n, a quotient and an integer. The first decimal would be a 1, so it may not be stored.

An exception is NaN (and zero?).
 

FAQ: How is a floating point number represented in binary?

What is Q and why would I use it instead of R?

Q is a programming language and environment used for data analysis and statistical computing. It is often used as an alternative to R due to its simplicity and speed. Q is also known for its user-friendly interface and extensive library of statistical functions.

How does Q compare to R in terms of functionality?

Q and R have similar functionalities and are both widely used in the scientific community. However, Q is known to have faster processing speed and better performance when dealing with large datasets. R, on the other hand, has a larger community and more diverse range of packages available.

Do I need to have programming experience to use Q?

Although having a basic understanding of programming can be helpful, Q is designed to be user-friendly and does not require extensive programming knowledge. Its graphical interface allows users to perform data analysis and statistical tests without writing any code.

Can I import data from R into Q?

Yes, Q has the capability to import data from various sources, including R. This allows users to take advantage of Q's speed and functionality while still being able to use data that was previously analyzed in R.

What types of analyses can I perform with Q?

Q has a wide range of statistical functions and tests available, including descriptive statistics, regression analysis, and hypothesis testing. It also has data visualization tools that allow for the creation of charts, graphs, and tables to display results.

Back
Top