Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Floating Point Numbers and Machine Precision. Start with x = 1.0 and keep dividi

ID: 3884083 • Letter: F

Question

Floating Point Numbers and Machine Precision. Start with x = 1.0 and keep dividing it by 2 until you get 0.0. If n +1 is the number of such divisions, then 1/2^n is the smallest number representable in the floating point format in the programming environment of your choice. Similarly, if at the stage m +1,1.0 + x 1.0, then 1.0 + 1/2^m is the floating point number closest to 1.0. Now start doubling 1.0 until you get + INF (or NaN) at some stage, N +1: then 2^N (2 - 1/2^m) is the largest floating point number. Obtain m, n, and N. Discuss your findings: deduce the numbers of bits that are used in your environment for the exponent and significand of the floating point numbers.

Explanation / Answer

The programming environment chosen here is python:

The number of bits used in python to represent exponent is 112 bits

Here in python version 3.5 and above the floating point values are rounded to 17 significant digits

A python implementation of the problem is given here and its is presented below along with its output.

The output shows the maximum and minimum value of the float and the approximate value of 1.0

Source code:

import math

x=1.0
n=0
#Dividing x by 2 until 0.0
while True:
         x=x/2
         if x== 0.0:
             break
         n+=1
  
#smallest number representable in floating point format

small_float= 1/(2**n)
print ("Small number representable in floating point format is : ",small_float)


x=1.0
m=0
#Finding the Closet Float
while True:
         x=x/2
         x_approx = x+1.0
         if x_approx == 1.0:
             break
         m+=1
close_float=1.0+(1/(2**(m)))
print ("Floating point number closest to 1.0 is : ",close_float)

#Largest floating point number in python

x=1.0
INF = math.inf
N=0
while True:
    x=x*2
    if x==INF:
        break
    N+=1


large_value= (2**N)*(2-(1/(2**m)))

print("Largest Floating point value is : ",large_value)

print(" --------------The values of M,n,N-------------")
print("The m Value is : ",m)
print("The n Value is : ",n)
print("The N Value is : ",N)


Output :