⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 atof.c

📁 ICCAVR软件的库函数源码
💻 C
字号:
/* Functions to perform various conversions to and from single-precision        */
/* floating point        2/ 8/00        E.M.Greene                              */
/* Adapted by rfm ImageCraft (see math2.c.save)                                 */
/* Modified (slightly) to accept expressions without decimal point, 7th Jan 2001 A.L.E.    */

#include <ctype.h>
#include <math.h>

float powi(int x, int y);

float atof(char *s)
 {
 float v = 0.0,
       scale = 0.1;
 char  mneg = ' ',
       eneg = ' ';
 int   e = 0;
	   
 while (isspace(*s))
  s++;

 if (*s == '-')
  mneg = *s++;
 else
  if (*s == '+')
   s++;
  
 while (isdigit(*s))
  v = 10.0 * v + *s++ - '0';
  
 if (*s == '.') 
  s++;
   
 while(isdigit(*s)) 
  {
  v += (*s++ - '0') * scale;
  scale /= 10.0;
  }
  
 if (toupper(*s) == 'E') 
  {
  s++;
  if (*s == '-')
   eneg = *s++;
  else 
   if (*s == '+')
    s++;
  while (isdigit(*s))
   e = 10 * e + *s++ - '0';
  if (eneg == '-')
   v = v / powi(10,e);
  else
   v = v * powi(10,e);
  }
  
 if (mneg == '-')
  v = -v;
   
 return v;
 }

float powi(int x, int y)
// Determines x-raised-to-the-power-of-y and returns the
// result as a float
 {
 int d;
 float p = 1;
 
 for (d = 0; d < y; d++)
  p *= x;
  
 return p;
 }

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -