My Project
Macros | Typedefs | Functions
iFloat.h File Reference

Defines interface of iFloat.c functions (do not modify) More...

Go to the source code of this file.

Macros

#define HALF
 
#define BITS   16
 
#define BITS_EXP   5
 
#define BITS_MANT   10
 
#define EXP_BIAS   15
 

Typedefs

typedef short iFloat_t
 

Functions

iFloat_t floatGetSign (iFloat_t x)
 
iFloat_t floatGetExp (iFloat_t x)
 
iFloat_t floatGetVal (iFloat_t x)
 
void floatGetAll (iFloat_t x, iFloat_t *sign, iFloat_t *exp, iFloat_t *val)
 
iFloat_t floatLeftMost1 (iFloat_t bits)
 
iFloat_t floatAbs (iFloat_t x)
 
iFloat_t floatNegate (iFloat_t x)
 
iFloat_t floatAdd (iFloat_t x, iFloat_t y)
 
iFloat_t floatSub (iFloat_t x, iFloat_t y)
 

Detailed Description

This file defines the interface to a C file iFloat.c that you will complete. You will learn how to do floating point arithmetic without using any float variables. Rather you will perform the operations by using the sign, exponent, and digit fields as defined in the IEEE Floating Point Standard.

Everything in a computer is stored as a series of 0/1's. When you use an int to type a value, you are telling the compiler (and ultimately the CPU) to treat the 0/1's as a two's complement number. When you use float, the 0/1's represent a floating point number. When an addition is performed, the computer knows whether to use the integer or floating point add instruction. The two instructions do different things to the 0/1's.

In this assignment, you are doing floating point operations without using floating point instructions. You are directly doing the bit manipulations necessary to complete the add. Since iFloat_t is an integral type, the compiler will generate integer instructions. The iFloat_t is to remind you (the programmer), that although the computer is going to treat all values as integers, you know it is really 3 values (sign, exponent, mantissa) packed into a single integer number. Your responsibility is to unpack the three pieces, do the operations necessary to complete the operation, then put the three pieces back together.

Function Documentation

iFloat_t floatAbs ( iFloat_t  x)

Absolute value of the argument. This can be done with a simple bit manipulation operation. No conditionals are required.

Parameters
xthe integer containing an IEEE floating point value
Returns
the absolute value of the parameter
Todo:
Implement based on documentation contained in iFloat.h
iFloat_t floatAdd ( iFloat_t  x,
iFloat_t  y 
)

Add two floating point values.

Parameters
xan integer containing an IEEE floating point value
yan integer containing an IEEE floating point value
Returns
x + y. Your code needs to account for a value of 0.0, but no other special cases (e.g. infinities).
Todo:
Implement based on documentation contained in iFloat.h
void floatGetAll ( iFloat_t  x,
iFloat_t *  sign,
iFloat_t *  exp,
iFloat_t *  val 
)

Get the sign, exponent, and value in a single call.

Parameters
xthe integer containing an IEEE floating point value
signpointer to location where the sign will be stored
exppointer to location where the exponent will be stored
valpointer to location where the value will be stored
Todo:
Implement based on documentation contained in iFloat.h
iFloat_t floatGetExp ( iFloat_t  x)

Extract the exponent of the argument.

Parameters
xthe integer containing an IEEE floating point value
Returns
the biased exponent of the argument
Todo:
Implement based on documentation contained in iFloat.h
iFloat_t floatGetSign ( iFloat_t  x)

Extract the sign of the argument.

Parameters
xthe integer containing an IEEE floating point value
Returns
0 if the value is 0 or positive, 1 if it is negative
Todo:
Implement based on documentation contained in iFloat.h
iFloat_t floatGetVal ( iFloat_t  x)

Extract the value of the argument. The value is the mantissa with the implicit 1 made explicit and adjusted for the sign of the argument. Please refer to the floating point addition example (step 1) in the instructions for an example on how the value is extracted. Basically, you'll have to do three things: 1) extract the mantissa; 2) set the implicit 1 in the extracted mantissa; 3) if the sign of the argument is negative, return the 2's complement of the mantissa from step (2). Otherwise, return it as-is. You may want to use the getField function from R3.

Parameters
xthe integer containing an IEEE floating point value
Returns
the bits representing the value. If x represents 0.0, you should still set the implicit 1 in the extracted mantissa.
Todo:
Implement based on documentation contained in iFloat.h
iFloat_t floatLeftMost1 ( iFloat_t  bits)

Obtain the position of the leftmost 1 in the argument's bits.

Parameters
bitsthe integer
Returns
-1 if the value is 0, otherwise the position (0 to 15) of the leftmost 1 bit. In a binary number, the positions are numbered from right to left with the rightmost position being 0.
Todo:
Implement based on documentation contained in iFloat.h
iFloat_t floatNegate ( iFloat_t  x)

Negate the argument. This can be done with a simple bit manipulation function. No conditionals are required. This is NOT the bitwise negation of the argument. As an example, if the argument represents 2.25, this function should return the IEEE bit pattern for -2.25.

Parameters
xthe integer containing an IEEE floating point value
Returns
the negation of the value. Note that the negation of 0.0 is 0.0 (not -0.0).
Todo:
Implement based on documentation contained in iFloat.h
iFloat_t floatSub ( iFloat_t  x,
iFloat_t  y 
)

Subtract two floating point values.

Parameters
xan integer containing an IEEE floating point value
yan integer containing an IEEE floating point value
Returns
x - y. Your code needs to account for a value of 0.0, but no other special cases (e.g. infinities).
Todo:
Implement based on documentation contained in iFloat.h