# How do I find the minimum and maximum of a represantable number with IEE 754 Single Precision Format

#### arhzz1

Joined Oct 21, 2020
57
Hello! Consider this homework problem
Consider the IEEE-754 format for Single Precision numbers. Provide your results in both IEEE-754 format (binary) and in decimal system.
a) Determine the smallest number ε such that 2 + ε > 2.
b) Determine the largest representable (positive or negative) number maxreal.
c) Determine the smallest representable (positive or negative) number minreal.

So what is actually confusing me is if a) is connected with b) and c). To elaborate, here is my attempt at solving these;

a) Since this is single precision the mantissa is 23 bits. Now to find epsilon we simply divide the smallest number the mantissa can have with 2^-23. The smallest number the mantissa can have is 1,000000000.0000

so I get for epsilon = 2^-23 = 1,19 * 10^-7 (roughly)

b) So for the maxreal (positive i tried the following) the leading bit (we called it so in class) s = 0 since we are positive,

for the exponent we have e = 127 and the biggest number we can represent with the mantissa M = 1,11111111111..111

so we use this formula -1^(s)*M*2^e so after plugging all of that in I get maxreal =1,89*10^38

for the negative it should simply be that s changes to 1 and the sign is now negative instead of positive;

Now I have not been able to verify if these are correct or not,and it seems to me that a) is not connected to b) and c) since they are simply applying the formulas we were given. Could anyone verify if this what I have written makes any sense?

Thanks!

#### WBahn

Joined Mar 31, 2012
30,290
Each of these questions is completely different.

Are you sure that adding 2^-23 to 2 will result in a value that is greater than 2?

If so, are you sure that no smaller value, when added to 2, will also do so?

You answered part (c) by just changing the sign -- but all that would do, assuming you answered part (b) correctly -- would be to go from the largest positive value to the largest negative value. Not what was asked.

#### arhzz1

Joined Oct 21, 2020
57
Okay so the questions are completely different, that part is cleared;

for a) I am pretty sure that it will be greater than 2 (if my calculator is not lyin) when i add 2^-23 to the result. Now is there a smaller value for epsilon that when added to 2 to fullfill the equation? I think no since that was the point of my calculation right? To find the smallest number and that should be 2^-23. We did a very similar example in class where the 2 was replaced with a 1 hence the equation was 1 + ε > 1. and this the steps we took to find the smallest number

is it worth pointing out that for a it says in brackets (which I did not include) (i.e Machine precision)

for b) I am confused; you said " would be to go from the largest positive value to the largest negative value. Not what was asked. " is that not what was asked? Or am I missing something.

#### WBahn

Joined Mar 31, 2012
30,290
Okay so the questions are completely different, that part is cleared;

for a) I am pretty sure that it will be greater than 2 (if my calculator is not lyin) when i add 2^-23 to the result. Now is there a smaller value for epsilon that when added to 2 to fullfill the equation? I think no since that was the point of my calculation right? To find the smallest number and that should be 2^-23. We did a very similar example in class where the 2 was replaced with a 1 hence the equation was 1 + ε > 1. and this the steps we took to find the smallest number
You can't rely one what your calculator is telling you, unless your calculator uses IEEE-754 single-precision floating point values (which it almost certainly is not).

By using the same steps for 2 + ε > 2 as you did for 1 + ε > 1, you are assuming that the presence of the 2 vs the 1 makes no difference.

What if the question had been to find the smallest value of ε such that 10^20 + ε > 10^20. Would you still conclude that the answer is ε = 2^-23?

is it worth pointing out that for a it says in brackets (which I did not include) (i.e Machine precision)

for b) I am confused; you said " would be to go from the largest positive value to the largest negative value. Not what was asked. " is that not what was asked? Or am I missing something.
What's the difference between "largest negative value" and "smallest negative value"?

Which is the smaller negative value, -10000, or -0.00001?

The term "smallest" here refers to magnitude.

#### arhzz1

Joined Oct 21, 2020
57
You can't rely one what your calculator is telling you, unless your calculator uses IEEE-754 single-precision floating point values (which it almost certainly is not).

By using the same steps for 2 + ε > 2 as you did for 1 + ε > 1, you are assuming that the presence of the 2 vs the 1 makes no difference.

What if the question had been to find the smallest value of ε such that 10^20 + ε > 10^20. Would you still conclude that the answer is ε = 2^-23?

What's the difference between "largest negative value" and "smallest negative value"?

Which is the smaller negative value, -10000, or -0.00001?

The term "smallest" here refers to magnitude.
Okay I see now, I think I have an undestanding where I want to end up with b) and c) b I basically need to calculate b) once and change the sign, the same one applies for c)

But for a) I see now that the "constant factor" of 2 changes the equation, but I feel like the steps that are taken should still apply, in the sense of the "algorithm" but the values in the algorithm itself will change. This was honestly my first intuition, but looking at how we calculated in class I never saw the "constant factors" in our case 1 and 2, come into play so I assumed it did not matter.

I fail to see, if the "algorithm" I am using to calculate a) where I need to make the adjustment to compensate for the change from 1 to 2.

#### WBahn

Joined Mar 31, 2012
30,290
The key is to understand the representation and not just be looking for some cookie cutter algorithm to turn a crank on whether you understand it or not.

Look at the representation for 2.0.

What is the next larger value that can be represented?

How do those to values relate to the value of ε that you seek?

Relate it back to a toy example in base-10 scientific notation.

You are able to represent a value using six sig figs. This means that if you want to represent 1234567890987654321.12345 that the best you can do is

1.23457 x 10^18

What is the next value greater than this that can be represented? Simple.

1.23458 x 10^18

So what is the smallest value that can be added to the first number such that the result is different?

0.00001 x 10^18 = 1.00000 x 10^13

Now, depending on the fine print (namely how the internal math is done and when rounding occurs), the answer MIGHT be half of that, but maybe not.

#### arhzz1

Joined Oct 21, 2020
57
The key is to understand the representation and not just be looking for some cookie cutter algorithm to turn a crank on whether you understand it or not.

Look at the representation for 2.0.

What is the next larger value that can be represented?

How do those to values relate to the value of ε that you seek?

Relate it back to a toy example in base-10 scientific notation.

You are able to represent a value using six sig figs. This means that if you want to represent 1234567890987654321.12345 that the best you can do is

1.23457 x 10^18

What is the next value greater than this that can be represented? Simple.

1.23458 x 10^18

So what is the smallest value that can be added to the first number such that the result is different?

0.00001 x 10^18 = 1.00000 x 10^13

Now, depending on the fine print (namely how the internal math is done and when rounding occurs), the answer MIGHT be half of that, but maybe not.
Okay so the thing that will change in the representation of 2.0 should be the exponent. We need 2^1 to represent the 2 and since the bias is 127 the exponent should be calculated as E = 1 - 127 = -126

Now we need to find the next value greater than 2.0 that can be represented. That should be when we add 2^(-23) to our value of 2.0, that should be our solution right?

#### WBahn

Joined Mar 31, 2012
30,290
Okay so the thing that will change in the representation of 2.0 should be the exponent. We need 2^1 to represent the 2 and since the bias is 127 the exponent should be calculated as E = 1 - 127 = -126
Go back and review how the exponent works in IEEE-754.

Now we need to find the next value greater than 2.0 that can be represented. That should be when we add 2^(-23) to our value of 2.0, that should be our solution right?
But you said that it was 2^(-23) when the question was for adding ε to 1. If it's still that when adding to a value of 2.0, why isn't it that when adding to a value of 10^20?

Write out the binary pattern for 2.0 as an IEEE single-precision floating point value?

Now write out the binary pattern for the value, as an IEEE single-precision floating point value, that is just barely larger than that?

What is that value? How much bigger than 2.0 is it?

#### arhzz1

Joined Oct 21, 2020
57
Go back and review how the exponent works in IEEE-754.

But you said that it was 2^(-23) when the question was for adding ε to 1. If it's still that when adding to a value of 2.0, why isn't it that when adding to a value of 10^20?

Write out the binary pattern for 2.0 as an IEEE single-precision floating point value?

Now write out the binary pattern for the value, as an IEEE single-precision floating point value, that is just barely larger than that?

What is that value? How much bigger than 2.0 is it?
Okay so binary pattern for 2.0

01000000000000000000000000000000

Now barely larger I will just add the smallest value I can add hence 2^-23

01000000000000000000000000000001

That value is 2^-23? I really dont see how it could be anything diffrent.

#### WBahn

Joined Mar 31, 2012
30,290
Okay so binary pattern for 2.0

01000000000000000000000000000000

Now barely larger I will just add the smallest value I can add hence 2^-23

01000000000000000000000000000001

That value is 2^-23? I really dont see how it could be anything diffrent.
So what if the question were what the smallest value that could be added to 2^100 to get a value different than 2^100?

2^100 =
01110001100000000000000000000000

Next value up
01110001100000000000000000000001

What is the equation that relates the components of the normalized IEEE-754 single-precision representation to the value it represents?

[S(1 bit)][E(8 bits)][M(23 bits)]

$$v \; = \; \left( -1 \right)^S \left( 1 \; + \; \frac{M}{2^{23}} \right) 2^{\left( E-127\right)}$$

You have v1 = 2 and v2 = 2 + ε

What is (v2 - v1)? Do the math.

#### arhzz1

Joined Oct 21, 2020
57
So what if the question were what the smallest value that could be added to 2^100 to get a value different than 2^100?

2^100 =
01110001100000000000000000000000

Next value up
01110001100000000000000000000001

What is the equation that relates the components of the normalized IEEE-754 single-precision representation to the value it represents?

[S(1 bit)][E(8 bits)][M(23 bits)]

$$v \; = \; \left( -1 \right)^S \left( 1 \; + \; \frac{M}{2^{23}} \right) 2^{\left( E-127\right)}$$

You have v1 = 2 and v2 = 2 + ε

What is (v2 - v1)? Do the math.
I think this is still a bit too complicated for me, I will wait for this problem to be solved in class and let the teacher explain it to me, I dont have a good enough grasp of the material to solve this.

Thanks for the help regardless

#### WBahn

Joined Mar 31, 2012
30,290
I think this is still a bit too complicated for me, I will wait for this problem to be solved in class and let the teacher explain it to me, I dont have a good enough grasp of the material to solve this.

Thanks for the help regardless
The you need to delve into the material to get a grasp that it good enough.

Let's walk through it for the 2^100 example.

$$v_1 \; = \; 2^{100} \; = \; \left( -1 \right)^S \left( 1 \; + \; \frac{M}{2^{23}} \right) 2^{\left( E-127\right)}$$

How is 2^100 represented?

$$v_1 \; = \; 2^{100} \; = \; \left( -1 \right)^{S_1} \left( 1 \; + \; \frac{M_1}{2^{23}} \right) 2^{\left( E_1 - 127\right)}$$

This requires S1=0, E1 = 227, M1=0

0 11100011 00000000000000000000000

Next value up from that S2=0, E2= 227, M2=1

0 11100011 00000000000000000000001

$$v_2 \; = \; 2^{100} \; + \; \epsilon \; = \; \left( -1 \right)^{S_2} \left( 1 \; + \; \frac{M_2}{2^{23}} \right) 2^{\left( E_2 - 127\right)}$$

Solve for ε

$$\epsilon \; = \; v_2 \; - \; v_1 \; = \; \left[ \left( -1 \right)^{S_2} \left( 1 \; + \; \frac{M_2}{2^{23}} \right) 2^{\left( E_2 - 127\right)} \right] \; - \; \left[ \left( -1 \right)^{S_1} \left( 1 \; + \; \frac{M_1}{2^{23}} \right) 2^{\left( E_1 - 127\right)} \right]$$

Do that math. It's all right there.

You are trying to learn how to be a scientist or engineer of some type -- that means that your primary job is to solve other peoples' problems. That means struggling through the hard work instead of just waiting for someone else to show you how it's done.

#### arhzz1

Joined Oct 21, 2020
57
The you need to delve into the material to get a grasp that it good enough.

Let's walk through it for the 2^100 example.

$$v_1 \; = \; 2^{100} \; = \; \left( -1 \right)^S \left( 1 \; + \; \frac{M}{2^{23}} \right) 2^{\left( E-127\right)}$$

How is 2^100 represented?

$$v_1 \; = \; 2^{100} \; = \; \left( -1 \right)^{S_1} \left( 1 \; + \; \frac{M_1}{2^{23}} \right) 2^{\left( E_1 - 127\right)}$$

This requires S1=0, E1 = 227, M1=0

0 11100011 00000000000000000000000

Next value up from that S2=0, E2= 227, M2=1

0 11100011 00000000000000000000001

$$v_2 \; = \; 2^{100} \; + \; \epsilon \; = \; \left( -1 \right)^{S_2} \left( 1 \; + \; \frac{M_2}{2^{23}} \right) 2^{\left( E_2 - 127\right)}$$

Solve for ε

$$\epsilon \; = \; v_2 \; - \; v_1 \; = \; \left[ \left( -1 \right)^{S_2} \left( 1 \; + \; \frac{M_2}{2^{23}} \right) 2^{\left( E_2 - 127\right)} \right] \; - \; \left[ \left( -1 \right)^{S_1} \left( 1 \; + \; \frac{M_1}{2^{23}} \right) 2^{\left( E_1 - 127\right)} \right]$$

Do that math. It's all right there.

You are trying to learn how to be a scientist or engineer of some type -- that means that your primary job is to solve other peoples' problems. That means struggling through the hard work instead of just waiting for someone else to show you how it's done.
Okay I will try this thank you.

Regarding the hard work, I am aware of that but I am simply not motivated to learn for this class. It is CS class (not an introductory class, the CS folks have it in their 4th semester) and for some reason it was put into the EE curriculum (I am an EE student) and I dont like it that much, it requires extreme amounts of self study (because all the first year classes that lead up to this class are not mandatory in our curriculum) and it can get very demanding since the amount of homework we have is pretty crazy.

#### joeyd999

Joined Jun 6, 2011
5,392
Okay I will try this thank you.

Regarding the hard work, I am aware of that but I am simply not motivated to learn for this class. It is CS class (not an introductory class, the CS folks have it in their 4th semester) and for some reason it was put into the EE curriculum (I am an EE student) and I dont like it that much, it requires extreme amounts of self study (because all the first year classes that lead up to this class are not mandatory in our curriculum) and it can get very demanding since the amount of homework we have is pretty crazy.
@arhzz1, one of the things I don't like about CS programmers is that they don't know how things work.

Learn how they work. You'll be a better programmer (more marketable) for it.

Edit: Oh, you're EE. You'll be a better engineer, then.

#### WBahn

Joined Mar 31, 2012
30,290
Okay I will try this thank you.

Regarding the hard work, I am aware of that but I am simply not motivated to learn for this class. It is CS class (not an introductory class, the CS folks have it in their 4th semester) and for some reason it was put into the EE curriculum (I am an EE student) and I dont like it that much, it requires extreme amounts of self study (because all the first year classes that lead up to this class are not mandatory in our curriculum) and it can get very demanding since the amount of homework we have is pretty crazy.
Leaving aside when, or if, number representations should be included in an EE curriculum, the most concerning aspect of this is about not being motivated to learn, for that or any class. I'm assuming that you would like to be a good, competent engineer (and maybe I'm wrong -- I've seen lots of engineering students that had no desire to actually be engineers and just wanted a piece of paper that supposedly pronounced that they were). So, under that assumption, good engineers tend to be people that seek out knowledge at every opportunity, because they want to know how things work and to build as deep a knowledge base as they can so that they can draw upon it in the future. You never know when something you learned years ago might be key to a completely unrelated problem. My first foray into designing asynchronous event-driven electronic circuits drew almost entirely upon my experience nearly two decades earlier with how the hydraulic event sequencing was done on the F-15 main landing gear system. I can't even begin to count how frequently knowledge about non-EE stuff has influenced my work as an EE.

As for number representations, it's far from only CS folks that benefit from that knowledge. I first learned about IEEE-754 in an EE setting, not a CS one, and it was before the World Wide Web was a going concern, so I spent hours in libraries and book stores tracking down information about it -- and that time has paid of handsomely over the years. It is something that is often included in an EE program's first-year programming course, particularly if that course is C-based. The math involved is also nothing beyond late middle school or early high school, so if it's the math that is holding you up, you really need to get a handle on that because EE is a very math-intensive discipline.