float
or double
types. Rather, you will
manipulate the bits of the floating point values using the two functions
provided to you, to get and set the bit-fields in a 32-bit word.
When you have completed this assignment you will understand how floating point
values are stored in the computer, and how to perform several operations in
the case where the underlying hardware/software does not provide floating
point support. This undesrstanding will be crucial later in the semester
because you will write similar programs for the LC3
computer,
which has no support for floating point.
First read the Getting Started section below and then study the documentation for flt32.h in the Files tab to understand the details of the assignment.
Save Target As..
for each of the files.
cd
command can be used for this.
make
You should see the following output:
/usr/bin/gcc -g -Wall -c -std=c99 flt32.c
/usr/bin/gcc -g -Wall -c -std=c99 testFlt32.c
/usr/bin/gcc -g -o testFlt32 field.o flt32.o testFlt32.o
./testFlt32
and read how to run the
the program.
./testFlt32 bin -3.6255
and you should see the output:
dec: -1066923983 hex: 0xC0680831 bin: 1100-0000-0110-1000-0000-1000-0011-0001
What you are seeing it the internal bit pattern of the floating point value
-3.625
expressed as an integer, as hex, and as binary.
You now have a functioning program. All the commands work, however, only bin
will produce correct results at this point.
flt32.c
,
study the documentation in found in the files tab.
Plan what you need to do before writing code.
The best way to complete the code is to follow a write/compile/test sequence. Do not attempt to write everything at once. Rather choose one function and do the following steps.
flt32.c
using your
favorite editor.field.c
using
make
. You will find it convenient to work with both a
terminal and editor window at the same time.You may work on the functions in any order, but most are very simple and are support functions for the meat of the code. A sample solution prepared by the author contained the following:
flt32_get_sign()
- 1 line of codeflt32_get_exp()
- 1 line of codeflt32_get_val()
- 1 line of codeflt32_abs()
- 1 line of codeflt32_sub()
- 1 line of codeflt32_get_all()
- 3 lines of codeflt32_negate()
- 3 lines of codeflt32_left_most_1()
- 10 lines of codeflt32_add()
- 60 lines of codefield.h
. Simply call those functions
from your code.
flt32_add()
is the only complex function in
this assignment. Many of the things you need to do can be done by calling the
support functions you have already written and thoroughly tested. The general algorithm for floating point addition is as follws:
flt32.c
using the
checkin
program. Use the name PA2. At the terminal
type:
~cs270/bin/checkin PA2 flt32.c
The above command submits your assignment. For a sanity check, type the following to get the file you checked in and make sure it compiles and runs properly with the provided files:
mkdir sanityCheck cd sanityCheck ~cs270/bin/peek PA2 flt32.c > flt32.c cp ../field.h ../field.o ../flt32.h ../testFlt32.c ../Makefile . make // Do LOTS of test cases.Relax, you are done with your assignment!