Question
What is the minimum number for N to calculate the value of ln x for x = 4.5 exactly as a half precision number? Use
What is the minimum number for N to calculate the value of ln x for x = 4.5 exactly as a half precision number? Use the function decimal2binary to answer this question.
MY FUNCTION
function [m,p,r] = decimal2binary(x,N)
%Input %x: decimal number to translate %N: number of mantissa bits to use. %output %m:vector of N mantissa bits %p: decimal exponent of the binary floating number %r: remainder
m = zeros(N,1); p = floor(log(x)/log(2));
n = p;
%calculate the remainder x taking the hidden bit into account x = x-2^n;
%loop over all requested mantissa bits for i = 1:N n = p-i; %working exponent of the i-th bit if 2^n <= x m(i) = 1; %set bit to 1 x = x-2^n; % update the remainder end end
%remainder r = x;
end
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started