x68/_round.c


DEFINITIONS

This source file includes following functions.
  1. _round


   1  /*
   2   * PROJECT C Library, X68000 PROGRAMMING INTERFACE DEFINITION
   3   * --------------------------------------------------------------------
   4   * This file is written by the Project C Library Group,  and completely
   5   * in public domain. You can freely use, copy, modify, and redistribute
   6   * the whole contents, without this notice.
   7   * --------------------------------------------------------------------
   8   * $Id: _round.c,v 1.1.1.2 1999/01/20 04:59:39 matz Exp $
   9   */
  10  /* changed 1997.2.2 by K.Okabe */
  11  
  12  /* System headers */
  13  #include <stdlib.h>
  14  #include <sys/xstdlib.h>
  15  
  16  /* Functions */
  17  int _round (char *top, char *cur, int undig)
  18  {
  19      char *ptr;
  20  
  21      /* 最後が5未満なら丸めは必要ない */
  22      if (undig < '5')
  23          return 0;
  24  
  25      /* ポインタ設定 */
  26      ptr = cur - 1;
  27  
  28      /* 先頭まで戻りながら丸め処理 */
  29      while (ptr >= top) {
  30  
  31          /* 繰り上がらなければそれで終わり */
  32          if (++(*ptr) <= '9')
  33              return 0;
  34  
  35          /* その桁を0に戻す */
  36          *ptr-- = '0';
  37  
  38      }
  39  
  40      /* 先頭を1にする */
  41      *++ptr = '1';
  42  
  43      /* 繰り上がりをしらせる */
  44      return 1;
  45  }