









Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!










MIPS floating-point arithmetic
MIPS floating-point arithmetic
integer load
(lw) to interpret them as an
int
— Use a
floating point load
(l.s) to interpret them as a
float
— Use a
branch
or a^
jump
(bne or j) to interpret them as an
instruction
MIPS floating-point arithmetic
^ IEEE numbers are stored using a kind of scientific notation.
±^ mantissa * 2
exponent
^ We can represent floating-point numbers with three binary fields: a signbit s, an exponent field e, and a fraction field f. ^ The IEEE 754 standard defines several different precisions.— Single precision numbers include an 8-bit exponent field and a 23-bit
fraction, for a total of 32 bits.— Double precision numbers have an 11-bit exponent field and a 52-bitfraction, for a total of 64 bits.
f
e s
MIPS floating-point arithmetic
^ The sign bit is 0 for positive numbers and 1 for negative numbers. ^ But unlike integers, IEEE values are stored in signed magnitude format.
f
e s
MIPS floating-point arithmetic
^ The e field represents the exponent as a biased number.— It contains the actual exponent
plus^
127 for single precision, or the
actual exponent
plus^
1023 in double precision.
— This converts all single-precision exponents from
unsigned numbers from 0 to 255, and all double-precision exponentsfrom^
— If e contains 01011101 (
), the actual exponent is 93 10
^ Storing a biased exponent
before
a normalized mantissa means we can
compare IEEE values as if they were signed integers.
f
e s
MIPS floating-point arithmetic
^ The decimal value of an IEEE number is given by the formula:
(1^ -^ 2s) * (1 + f) * 2
e-bias
^ Here, the s, f and e fields are assumed to be in decimal.— (
-^ 2s) is 1 or
— We add an implicit 1 to the fraction field f, as mentioned earlier.— Again, the bias is either 127 or 1023, for single or double precision.
f
e s
MIPS floating-point arithmetic
^ Let’s find the decimal value of the following IEEE number.
^ First convert each individual field to decimal.— The sign bit s is 1.— The e field contains 01111100 = 124
— The mantissa is 0.11000… = 0.
^ Then just plug these decimal values of s, e and f into our formula.
(1^ -^ 2s) * (1 + f) * 2
e-bias
^ This gives us (
124-
MIPS floating-point arithmetic
^ What is the single-precision representation of 347.625?1.
First convert the number to binary: 347.625 = 101011011.
2.^ Normalize the number by shifting the binary point until there is asingle 1 to the left:101011011.101 x 2
0 =^ 1.01011011101 x 2
8
3.^ The bits to the right of the binary point comprise the fractional fieldf. 4.^ The number of times you shifted gives the exponent. The field eshould contain: exponent + 127.5.^ Sign bit: 0 if positive, 1 if negative.
MIPS floating-point arithmetic
With four significant digits, this gets rounded to:This can result in a loss of least significant digits—the rightmost 1 in thiscase. But rewriting the number with the larger exponent could result inloss of the
most
significant digits, which is much worse.
MIPS floating-point arithmetic
This step may cause the point to shift either left or right, and theexponent to either increase or decrease.4. Round the number if needed.
2 gets rounded to
, or^
. The correct answer is 100.151, so we have
the right answer to four significant digits, but there’s a small error already.
MIPS floating-point arithmetic
MIPS floating-point arithmetic
^ The IEEE 754 standard defines number representations and operations forfloating-point arithmetic. ^ Having a finite number of bits means we can’t represent all possible realnumbers, and errors will occur from approximations.