Single precision floating point

In summary: That's what I assume the rule is for rounding. I think there's a special case where the next bit is 0, but the bit after that is 1, in which case you have to round to the nearest even number.
  • #1
Maybe_Memorie
353
0

Homework Statement



Convert 80/9 to single-precision floating-point.

Homework Equations





The Attempt at a Solution



Right, I don't understand this at all but I'm trying to follow my notes, not very successfully..

80/9 is positive so the sign bit is 0.

Exponent is adjusted so the mantissa is between 1 and 2, so we get 8x(10/9)
The true exponent is 3.

Use binary long division to calculate 10/9 as a recurring binary point number.
9 = (1001)
10 = (1010)

It results with 1.00011 00011 00011 ...

Next he does a geometric series and says "The group 000111 represents 7/64".


I'm lost. Can someone please explain where he's getting 000111 and 7/64 please?
Thank you! :D
 
Physics news on Phys.org
  • #2
Maybe_Memorie said:

Homework Statement



Convert 80/9 to single-precision floating-point.

Homework Equations





The Attempt at a Solution



Right, I don't understand this at all but I'm trying to follow my notes, not very successfully..

80/9 is positive so the sign bit is 0.

Exponent is adjusted so the mantissa is between 1 and 2, so we get 8x(10/9)
The true exponent is 3.

Use binary long division to calculate 10/9 as a recurring binary point number.
9 = (1001)
10 = (1010)

It results with 1.00011 00011 00011 ...

Next he does a geometric series and says "The group 000111 represents 7/64".


I'm lost. Can someone please explain where he's getting 000111 and 7/64 please?
Thank you! :D

Think of 000111 being to the right of a "binary" point (instead of decimal point). The leftmost zero is in the 1/2's place (2-1). The next zero is in the 1/4 th's place (2-2), and so on.

So 000111 represents 0 * 1/2 + 0 * 1/4 + 0 * 1/8 + 1 * 1/16 + 1 * 1/32 + 1 * 1/64

If you add the three fractions on the right, what do you get?
 
  • #3
You get 7/64 :smile:

But I don't see where 000111 came from, as in his solution it's 00011 that's recurring. :confused:
 
  • #4
Maybe_Memorie said:
It results with 1.00011 00011 00011 ...

Next he does a geometric series and says "The group 000111 represents 7/64".

I'm lost. Can someone please explain where he's getting 000111 and 7/64 please?
The binary expansion you wrote is incorrect. It should be 1.000111 000111 000111… That's where he got 000111 from, if that's what you were wondering.
 
  • #5
Wait, I see it now! :smile:

So he uses a geometric series and gets 10/9, which shows the result is correct.

He continues the fractional part until it exceeds 23 bits
.00011100011100011100011

He then gets the required number in binary and I've no idea how :confused:
 
  • #6
Now, as to where the 000111 comes from,

It results with 1.00011 00011 00011

This part is, I believe, incorrect. I did the division myself, and got 1.000111 000111 000111... To be honest I quit after 1.000111, but I'm reasonably sure that the part that repeats is 000111, which is what you were asking about, and is different from the results I quoted.
 
  • #7
80/9 is equal to 8.888…, which in binary is 1000.111000111000…2. Converting to binary is the first thing you have to know how to do. There are techniques you can use to crank this out relatively quickly.

Now you want to write this in base-2 scientific notation: 1.000111000111…x23.

From here, it's easy to construct the floating-point representation. The number is positive, so the first bit is 0. The exponent is 3. You add 127 to it, which gives 130=100000102, which are the next eight bits. Finally, the first digit of the mantissa will always be a 1, so you can drop it and just copy the first 23 bits following the binary point. Putting it all together, you get

80/9 = 0 10000010 00011100011100011100011
 
  • #8
Okay I understand so far. :smile:

However my lecturer gets an answer of
0 1000 0010 000111 000111 000111 00100
= 0100 0001 0000 1110 0011 1000 1110 0100 =
= 4 1 0 e 3 8 e 4

I understand how he goes from the first line to the second to the third, but not where the first line comes from.
 
  • #9
How to get the first line is what I explained in my previous post!
 
  • #10
That's what I assumed but it threw me off seeing 00100 at the end of his first line because this doesn't appear anywhere else
 
  • #11
Ah, I didn't notice that. [STRIKE]That's just a mistake on his part. The last four bits should be 0011, and the last hexadecimal digit should be 3.[/STRIKE]

I just realized it's due to rounding. The next bit would have been a 1, so you round up and 3 becomes a 4.
 
  • #12
vela said:
[STRIKE]That's just a mistake on his part. The last four bits should be 0011, and the last hexadecimal digit should be 3.[/STRIKE]

I wouldn't rule that out. His notes, especially his Group theory ones, are full of mistakes and paradoxes. :rolleyes:


Thanks very much for the help! :)
 
  • #13
vela said:
I just realized it's due to rounding. The next bit would have been a 1, so you round up and 3 becomes a 4.
That's my thought, too. Do you know if there's a rule so that when the next bit is 0, you truncate, and if it's a 1, you round up?
 
  • #14
I think so. It's mentioned in the Wikipedia article on floating-point representation.
 
  • #15
The IEEE standard specifies 5 rounding algorithms:
http://en.wikipedia.org/wiki/IEEE_754-2008#Rounding_algorithms

However, in practice you'd always want to minimize the error in floating point arithmetic, meaning you'd round to the nearest representation.
In this case that means rounding up (without a tie).
 

1. What is single precision floating point?

Single precision floating point is a data type commonly used in computer programming to represent real numbers with a limited amount of memory. It is typically represented by 32 bits, with 1 bit for the sign, 8 bits for the exponent, and 23 bits for the mantissa.

2. How is single precision floating point different from double precision floating point?

The main difference between single precision and double precision floating point is the amount of memory used to represent a number. Single precision uses 32 bits, while double precision uses 64 bits. This means that double precision can represent a wider range of numbers with higher precision compared to single precision.

3. What is the range of numbers that can be represented with single precision floating point?

The range of numbers that can be represented with single precision floating point is approximately 1.2 x 10^-38 to 3.4 x 10^38. This range can vary slightly depending on the implementation, but it is typically much larger than what can be represented with integers.

4. What are some potential issues with using single precision floating point?

One potential issue with using single precision floating point is that it is not always able to accurately represent certain numbers, leading to rounding errors. Additionally, the limited number of bits used for the mantissa can result in loss of precision when performing calculations.

5. How is single precision floating point used in scientific computing?

Single precision floating point is commonly used in scientific computing because it allows for a wide range of numbers to be represented with relatively small memory usage. However, for applications that require high precision, such as weather forecasting or nuclear simulations, double precision floating point is often preferred.

Similar threads

  • Computing and Technology
Replies
4
Views
763
Replies
4
Views
926
  • Engineering and Comp Sci Homework Help
Replies
10
Views
3K
Replies
6
Views
9K
  • Engineering and Comp Sci Homework Help
Replies
5
Views
5K
  • Engineering and Comp Sci Homework Help
Replies
1
Views
2K
  • Engineering and Comp Sci Homework Help
Replies
5
Views
9K
  • Programming and Computer Science
Replies
23
Views
4K
  • Engineering and Comp Sci Homework Help
Replies
0
Views
2K
  • General Engineering
Replies
4
Views
4K
Back
Top