float
or double
types. Rather, you will manipulate
the bits of the floating point values using the field code you wrote in a
previous assignment. You will also learn simple pointer operations using C's
address-of operator (&) and dereference operator
(*).
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. For example, the LC3
computer you will use later
in this course has no floating point support.
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.
field.h
(do not modify)field.c
from your previous assignmentflt32.c
(complete this file)flt32.h
(do not modify)testFlt32.c
(do not modify)Makefile
(do not modify)cd
command can be used for this.
make
You should see the following output:
/usr/bin/gcc -g -Wall -c -std=c11 field.c
/usr/bin/gcc -g -Wall -c -std=c11 flt32.c
/usr/bin/gcc -g -Wall -c -std=c11 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.625
and you should see the output:
dec: -1066926080 hex: 0xC0680000 bin: 1100-0000-0110-1000-0000-0000-0000-0000
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.c
. Simply call
those methods from your code. Do NOT copy code from field.c
into this file.
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 methods 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 PAx. At the terminal
type:
~cs270/bin/checkin PAx 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 PAx flt32.c > flt32.c cp ../field.h ../field.c ../flt32.h ../testFlt32.c ../Makefile . make // Do LOTS of test cases.Relax, you are done with your assignment!