rts-char.c

     
   1  //! @file rts-char.c
   2  //! @author J. Marcel van der Veer
   3  //
   4  //! @section Copyright
   5  //
   6  // This file is part of VIF - vintage FORTRAN compiler.
   7  // Copyright 2020-2025 J. Marcel van der Veer <algol68g@xs4all.nl>.
   8  //
   9  //! @section License
  10  //
  11  // This program is free software; you can redistribute it and/or modify it 
  12  // under the terms of the GNU General Public License as published by the 
  13  // Free Software Foundation; either version 3 of the License, or 
  14  // (at your option) any later version.
  15  //
  16  // This program is distributed in the hope that it will be useful, but 
  17  // WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY 
  18  // or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for 
  19  // more details. You should have received a copy of the GNU General Public 
  20  // License along with this program. If not, see <http://www.gnu.org/licenses/>.
  21  
  22  //! @section Synopsis
  23  //!
  24  //! Runtime support for character - integer/real conversion.
  25  
  26  #include <vif.h>
  27  
  28  int_4 _str_to_int4 (char *str)
  29  {
  30    int_4 sum = 0, fact = 1, len = strlen (str);
  31    for (int_4 k = 0; k < 4 && k < len; k++) {
  32      sum += fact * (int_4) str[k];
  33      fact <<= CHAR_BIT;
  34    }
  35    return sum;
  36  }
  37  
  38  real_8 _str_to_real8 (char *str)
  39  {
  40    real_8 sum = 0.0;
  41    int_8 fact = 1, len = strlen (str);
  42    for (int_4 k = 0; k < (DBL_MANT_DIG / CHAR_BIT) && k < len; k++) {
  43      sum += fact * (int_4) str[k];
  44      fact <<= CHAR_BIT;
  45    }
  46    return sum;
  47  }
  48  
     


© 2002-2025 J.M. van der Veer (jmvdveer@xs4all.nl)