Subversion Repositories Kolibri OS

Rev

Go to most recent revision | Blame | Last modification | View Log | Download | RSS feed

  1. /*
  2.  * round_generic.c
  3.  *
  4.  * $Id: round_generic.c,v 1.1 2008/06/03 18:42:21 keithmarshall Exp $
  5.  *
  6.  * Provides a generic implementation for the `round()', `roundf()'
  7.  * and `roundl()' functions; compile with `-D FUNCTION=name', with
  8.  * `name' set to each of these three in turn, to create separate
  9.  * object files for each of the three functions.
  10.  *
  11.  * Written by Keith Marshall <keithmarshall@users.sourceforge.net>
  12.  *
  13.  * This is free software.  You may redistribute and/or modify it as you
  14.  * see fit, without restriction of copyright.
  15.  *
  16.  * This software is provided "as is", in the hope that it may be useful,
  17.  * but WITHOUT WARRANTY OF ANY KIND, not even any implied warranty of
  18.  * MERCHANTABILITY, nor of FITNESS FOR ANY PARTICULAR PURPOSE.  At no
  19.  * time will the author accept any form of liability for any damages,
  20.  * however caused, resulting from the use of this software.
  21.  *
  22.  */
  23. #ifndef FUNCTION
  24. /*
  25.  * Normally specified with `-D FUNCTION=name', on the command line.
  26.  * Valid FUNCTION names are `round', `roundf' and `roundl'; specifying
  27.  * anything else will most likely cause a compilation error.  If user
  28.  * did not specify any FUNCTION name, default to `round'.
  29.  */
  30. #define FUNCTION round
  31. #endif
  32.  
  33. #include "round_internal.h"
  34.  
  35. /* Generic implementation.
  36.  * The user is required to specify the FUNCTION name;
  37.  * the RETURN_TYPE and INPUT_TYPE macros resolve to appropriate
  38.  * type declarations, to match the selected FUNCTION prototype.
  39.  */
  40. RETURN_TYPE FUNCTION( INPUT_TYPE x )
  41. {
  42.   /* Round to nearest integer, away from zero for half-way.
  43.    *
  44.    * We split it with the `round_internal()' function in
  45.    * a private header file, so that it may be shared by this,
  46.    * `lround()' and `llround()' implementations.
  47.    */
  48.   return isfinite( x ) ? round_internal( x ) : x;
  49. }
  50.  
  51. /* $RCSfile: round_generic.c,v $$Revision: 1.1 $: end of file */
  52.