Home / Expert Answers / Computer Science / implementation-in-python-please-provide-source-code-and-check-against-the-following-correct-out-pa334

(Solved): Implementation in Python! Please provide source code, and check against the following (correct out ...



Write a function, ulps(x,y), that takes two floating point parameters, \( \mathbf{x} \) and \( \mathbf{y} \), and returns the

Implementation in Python! Please provide source code, and check against the following (correct outputs are in the comments in the corresponding line):

\( \begin{array}{lll}\text { print (ulps }(-1.0,-1.0000000000000003) & / / 1 \\ \text { print (ulps }(1.0,1.0000000000000003)

There is already an answer on Chegg for a similar question, that solution is not correct. Please do not provide that solution again! Thank you!

Write a function, ulps(x,y), that takes two floating point parameters, and , and returns the number of ulps (floating-point intervals) between and . You will of course need to take into account that and may have different exponents of the floating-point base in their representation. Also, do not assume that (handle either case). Your function may assume that its parameter will be the floating-point type. Do not use logarithms to find the exponent of your floating-point numbers - use repeated multiplication/division following the pattern discussed in class. Your function should handle negative numbers and numbers less than 1. Your function will return infinity if the input parameters have the following properties: - Opposite in signs, or - Either one of them is zero, or - Either one of them is either positive infinity or negative infinity. If the input parameters are both negative, convert them to be positive numbers by taking the absolute value. Your algorithm only needs to work with two positive floating-point numbers. The following code segment shows how to use math and sys modules to get the base, infinity (inf), machine epsilon (eps), and mantissa digits (prec) in Python. import sys import math base = sys.float_info.radix eps = sys.float info.epsilon prec = sys.float_info.mant_dig inf = math.inf


We have an Answer from Expert

View Expert Answer

Expert Answer


def ulps(x, y): import sys import math base = sys.float_info.radix eps = sys.float_info.epsilon prec = sys.float_i
We have an Answer from Expert

Buy This Answer $5

Place Order

We Provide Services Across The Globe