#ifndef __FLT32_H__ #define __FLT32_H__ /* * flt32.h - header for simple floating point functions. * * "Copyright (c) 2014 by Fritz Sieker." * * Permission to use, copy, modify, and distribute this software and its * documentation for any purpose, without fee, and without written * agreement is hereby granted, provided that the above copyright notice * and the following two paragraphs appear in all copies of this software. * * IN NO EVENT SHALL THE AUTHOR BE LIABLE TO ANY PARTY FOR DIRECT, * INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES ARISING OUT * OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF THE AUTHOR * HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * * THE AUTHOR SPECIFICALLY DISCLAIMS ANY WARRANTIES, INCLUDING, BUT NOT * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR * A PARTICULAR PURPOSE. THE SOFTWARE PROVIDED HEREUNDER IS ON AN "AS IS" * BASIS, AND THE AUTHOR NO OBLIGATION TO PROVIDE MAINTENANCE, SUPPORT, * UPDATES, ENHANCEMENTS, OR MODIFICATIONS." */ /** @file flt32.h * @brief Defines interface of flt32.c functions (do not modify) * @details This file defines the interface to a C file flt32.c that * you will complete. You will learn how to do floating point arithmatic * 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. * You may reuse the code you wrote for field.c assignment. * Or, you may use the provided file field.o in place of your * code. That file is a compiled version of field.c written * by an instructor. * You will only be submitting one files (flt32.c). */ /** Whenever flt32 is used, the value is an integer in the * IEEE floating point 32 bit standard. */ typedef int flt32; /** Extract the sign of the argument * @param x the integer containing a IEEE floating point value * @return 0 if the value is 0 or positive, 1 if it is negative */ int flt32_get_sign (flt32 x); /** Extract the exponent of the argument * @param x the integer containing a IEEE floating point value * @return the exponent of the argument, after removing bias */ int flt32_get_exp (flt32 x); /** Extract the digits of the argument * @param x the integer containing a IEEE floating point value * @return the 24 bits representing the value (includes the implicit 1) */ int flt32_get_val (flt32 x); /** Get the sign, value, and exponent in a single call. You will use * @param x the integer containing a IEEE floating point value * @param sign pointer to location where sign will be stored * @param val pointer to location where value will be stored * @param exp pointer to location where exponent will be stored * C pointers to return values. */ void flt32_get_sve(flt32 x, int *sign, int *val, int *exp); /** Extract the position of the leftmost 1 in the argument's bits * @param value the integer * @return -1 if the value is 0, otherwise the position (0 to 31) of the left * most 1 bit. */ int flt32_leftmost_1 (int value); /** Absolute value of the argument. This can be done with a simple bit * manipulation operation or with your field functions. No * conditionals are required. * @param x some pattern of bits (may be a IEEE floating point value) * @return the absolute value of the parameter */ flt32 flt32_abs (flt32 x); /** Negate the argument. This can be done with a simple bit manipulation * function (think about the C xor operator (^) or with * your field functions. * @param x the integer containing a IEEE floating point value * @return the negation of the value */ flt32 flt32_negate (flt32 x); /** Add two floating point values * @param x an integer containing a IEEE floating point value * @param y an integer containing a IEEE floating point value * @return x + y. Your code needs to account for a value of 0.0, but no other * special cases (e.g. infinities) */ flt32 flt32_add (flt32 x, flt32 y); /** Subtract to floating point values * @param x an integer containing a IEEE floating point value * @param y an integer containing a IEEE floating point value * @return x - y. Your code needs to account for a value of 0.0, but no other * special cases (e.g. infinities) */ flt32 flt32_sub (flt32 x, flt32 y); #endif