开源 企业版 高校版 私有云 模力方舟 AI 队友
代码拉取完成,页面将自动刷新
加入 Gitee
与超过 1400万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
已有帐号? 立即登录
文件
master
分支 (1)
master
master
分支 (1)
master
克隆/下载
克隆/下载
提示
下载代码请复制以下命令到终端执行
为确保你提交的代码身份被 Gitee 正确识别,请执行以下命令完成配置
初次使用 SSH 协议进行代码克隆、推送等操作时,需按下述提示完成 SSH 配置
1 生成 RSA 密钥
2 获取 RSA 公钥内容,并配置到 SSH公钥
在 Gitee 上使用 SVN,请访问 使用指南
使用 HTTPS 协议时,命令行会出现如下账号密码验证步骤。基于安全考虑,Gitee 建议 配置并使用私人令牌 替代登录密码进行克隆、推送等操作
Username for 'https://gitee.com': userName
Password for 'https://userName@gitee.com': # 私人令牌
master
分支 (1)
master
python
/
Python
/
strtod.c
python
/
Python
/
strtod.c
strtod.c 5.08 KB
一键复制 编辑 原始数据 按行查看 历史
feng 提交于 2015年10月01日 10:15 +08:00 . python
#include "pyconfig.h"
/* comp.sources.misc strtod(), as posted in comp.lang.tcl,
with bugfix for "123000.0" and acceptance of space after 'e' sign nuked.
************************************************************
* YOU MUST EDIT THE MACHINE-DEPENDENT DEFINITIONS BELOW!!! *
************************************************************
*/
/* File : stdtod.c (Modified version of str2dbl.c)
Author : Richard A. O'Keefe @ Quintus Computer Systems, Inc.
Updated: Tuesday August 2nd, 1988
Defines: double strtod (char *str, char**ptr)
*/
/* This is an implementation of the strtod() function described in the
System V manuals, with a different name to avoid linker problems.
All that str2dbl() does itself is check that the argument is well-formed
and is in range. It leaves the work of conversion to atof(), which is
assumed to exist and deliver correct results (if they can be represented).
There are two reasons why this should be provided to the net:
(a) some UNIX systems do not yet have strtod(), or do not have it
available in the BSD "universe" (but they do have atof()).
(b) some of the UNIX systems that *do* have it get it wrong.
(some crash with large arguments, some assign the wrong *ptr value).
There is a reason why *we* are providing it: we need a correct version
of strtod(), and if we give this one away maybe someone will look for
mistakes in it and fix them for us (:-).
*/
/* The following constants are machine-specific. MD{MIN,MAX}EXPT are
integers and MD{MIN,MAX}FRAC are strings such that
0.${MDMAXFRAC}e${MDMAXEXPT} is the largest representable double,
0.${MDMINFRAC}e${MDMINEXPT} is the smallest representable +ve double
MD{MIN,MAX}FRAC must not have any trailing zeros.
The values here are for IEEE-754 64-bit floats.
It is not perfectly clear to me whether an IEEE infinity should be
returned for overflow, nor what a portable way of writing one is,
so HUGE is just 0.MAXFRAC*10**MAXEXPT (this seems still to be the
UNIX convention).
I do know about <values.h>, but the whole point of this file is that
we can't always trust that stuff to be there or to be correct.
*/
static int MDMINEXPT = -323;
static char MDMINFRAC[] = "494065645841246544";
static double ZERO = 0.0;
static int MDMAXEXPT = 309;
static char MDMAXFRAC[] = "17976931348623157";
static double HUGE = 1.7976931348623157e308;
extern double atof(const char *); /* Only called when result known to be ok */
#ifdef HAVE_ERRNO_H
#include <errno.h>
#endif
extern int errno;
double strtod(char *str, char **ptr)
{
int sign, scale, dotseen;
int esign, expt;
char *save;
register char *sp, *dp;
register int c;
char *buforg, *buflim;
char buffer[64]; /* 45-digit significant + */
/* 13-digit exponent */
sp = str;
while (*sp == ' ') sp++;
sign = 1;
if (*sp == '-') sign -= 2, sp++;
dotseen = 0, scale = 0;
dp = buffer;
*dp++ = '0'; *dp++ = '.';
buforg = dp, buflim = buffer+48;
for (save = sp; c = *sp; sp++)
if (c == '.') {
if (dotseen) break;
dotseen++;
} else
if ((unsigned)(c-'0') > (unsigned)('9'-'0')) {
break;
} else
if (c == '0') {
if (dp != buforg) {
/* This is not the first digit, so we want to keep it */
if (dp < buflim) *dp++ = c;
if (!dotseen) scale++;
} else {
/* No non-zero digits seen yet */
/* If a . has been seen, scale must be adjusted */
if (dotseen) scale--;
}
} else {
/* This is a nonzero digit, so we want to keep it */
if (dp < buflim) *dp++ = c;
/* If it precedes a ., scale must be adjusted */
if (!dotseen) scale++;
}
if (sp == save) {
if (ptr) *ptr = str;
errno = EDOM; /* what should this be? */
return ZERO;
}
while (dp > buforg && dp[-1] == '0') --dp;
if (dp == buforg) *dp++ = '0';
*dp = '0円';
/* Now the contents of buffer are
+--+--------+-+--------+
|0.|fraction|\|leftover|
+--+--------+-+--------+
^dp points here
where fraction begins with 0 iff it is "0", and has at most
45 digits in it, and leftover is at least 16 characters.
*/
save = sp, expt = 0, esign = 1;
do {
c = *sp++;
if (c != 'e' && c != 'E') break;
c = *sp++;
if (c == '-') esign -= 2, c = *sp++; else
if (c == '+' /* || c == ' ' */ ) c = *sp++;
if ((unsigned)(c-'0') > (unsigned)('9'-'0')) break;
while (c == '0') c = *sp++;
for (; (unsigned)(c-'0') <= (unsigned)('9'-'0'); c = *sp++)
expt = expt*10 + c-'0';
if (esign < 0) expt = -expt;
save = sp-1;
} while (0);
if (ptr) *ptr = save;
expt += scale;
/* Now the number is sign*0.fraction*10**expt */
errno = ERANGE;
if (expt > MDMAXEXPT) {
return HUGE*sign;
} else
if (expt == MDMAXEXPT) {
if (strcmp(buforg, MDMAXFRAC) > 0) return HUGE*sign;
} else
if (expt < MDMINEXPT) {
return ZERO*sign;
} else
if (expt == MDMINEXPT) {
if (strcmp(buforg, MDMINFRAC) < 0) return ZERO*sign;
}
/* We have now established that the number can be */
/* represented without overflow or underflow */
(void) sprintf(dp, "E%d", expt);
errno = 0;
return atof(buffer)*sign;
}
Loading...
举报
举报成功
我们将于2个工作日内通过站内信反馈结果给你!
请认真填写举报原因,尽可能描述详细。
请选择举报类型
取消
发送
误判申诉

此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。

如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。

取消
提交

简介

github.com clone
暂无标签
未知许可证
查看未知开源许可协议
取消

发行版

暂无发行版

贡献者

全部

近期动态

不能加载更多了
编辑仓库简介
简介内容
主页
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Python
1
https://gitee.com/yf33/python.git
git@gitee.com:yf33/python.git
yf33
python
python
master
点此查找更多帮助

搜索帮助

评论
仓库举报
回到顶部
登录提示
该操作需登录 Gitee 帐号,请先登录后再操作。
立即登录
没有帐号,去注册

AltStyle によって変換されたページ (->オリジナル) /