My Project
Functions
testFloat.c File Reference

Driver to test functions of iFloat.c (do not modify) More...

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <stdbool.h>
#include <stdarg.h>
#include "Debug.h"
#include "convert.h"
#include "iFloat.h"

Functions

const char * getBinaryMSB (int value, int msb)
 
const char * getBinary (iFloat_t value)
 
int main (int argc, const char *argv[])
 

Detailed Description

This is a driver program to test the functions defined in iFloat.h and implemented in iFloat.c. The program takes one or more command line parameters and calls one of the methods, then prints the results. To see how to use the program, execute testFloat in a terminal window. This will print a usage statement defining how to run the program. The first "logical" parameter of the program is always a key defining which function to run. It may be optionally preceeded by -debug to turn on debugging. The options are:

A sample execution might be: testFloat abs -2.5

which prints

abs(-2.5) --> 2.500000

To use the bin option do testFloat bin 1.5

which prints

dec: 15872  hex: 0x3E00  bin: 0011-1110-0000-0000

This is the decimal, hex and binary representation of the floating point number 1.5. You will find the bin option very useful as you can determine what the correct representation of the answer should be. To test you program, choose values where the correct answer is easy to compute in your head. Then use the bin option to determine what the answer looks like. Finally, run your program and if your answer differs from the answer you computed, use the bin option to see the pattern of your answer. Then you need to read your program, perhaps add debugging output (using the debug() function), and determine what your program is actually doing.

Author
Fritz Sieker

Function Documentation

const char* getBinary ( iFloat_t  value)

Get a 16/32 bit binary representation of a value.

Parameters
valuethe value to be converted to binary
Returns
a string of bits with a separator every four characters
const char* getBinaryMSB ( int  value,
int  msb 
)

Get the binary representation of a value starting at the specified bit position. A separator is printed every 4 bits for easy reading. This function return a pointer to a static buffer, so that the result must be used, before it is called again. In particular, you may NOT have multiple calls to this function in a single DEBUG() call.

Parameters
valuethe value to be converted to binary
msbthe bit position to begin printing (31 to 0)
Returns
a string of bits with a separator every four characters
int main ( int  argc,
const char *  argv[] 
)

Entry point of the program

Parameters
argccount of arguments, will always be at least 1
argvarray of parameters to program argv[0] is the name of the program, so additional parameters will begin at index 1.
Returns
0 the Linux convention for success.