将 IEEE 754 double 转换为字符串的算法? [英] Algorithm to convert an IEEE 754 double to a string?

查看:20
本文介绍了将 IEEE 754 double 转换为字符串的算法?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

许多使用 IEEE 754 双精度的编程语言提供了一个库函数来将这些双精度转换为字符串.比如C有sprintf,C++有stringstream,Java有Double.toString

Many programming languages that use IEEE 754 doubles provide a library function to convert those doubles to strings. For example, C has sprintf, C++ has stringstream, Java has Double.toString, etc.

在内部,这些功能是如何实现的?也就是说,鉴于它们经常受到程序员选择的精度限制,它们使用什么算法将双精度值转换为字符串表示?

Internally, how are these functions implemented? That is, what algorithm(s) are they using to convert the double into a string representation, given that they are often subject to programmer-chosen precision limitations?

谢谢!

推荐答案

各种软件环境用于将浮点数转换为字符串表示的代码通常基于以下出版物(Steele 和 White 的工作特别频繁引用):

The code used by various software environments to convert floating-point numbers to string representations is typically based on the following publications (the work by Steele and White is particularly frequently cited):

Jerome T. Coonen:浮点运算标准的实施指南".计算机,卷.13, No. 1, January 1980, pp. 68-79

Jerome T. Coonen: "An Implementation Guide to a Proposed Standard for Floating-Point Arithmetic." Computer, Vol. 13, No. 1, January 1980, pp. 68-79

伙计.L. Steele Jr. 和 J. L. White:如何准确打印浮点数".在ACM SIGPLAN '90 编程语言设计与实现会议的会议记录中,纽约怀特普莱恩斯,1990 年 6 月,第 112-126 页

Guy. L. Steele Jr. and J. L. White: "How to print floating-point numbers accurately". In proceedings of ACM SIGPLAN '90 Conference on Programming Language Design and Implementation, White Plains, New York, June 1990, pp. 112-126

David M. Gay:正确四舍五入的二进制-十进制和十进制-二进制转换."技术报告 90-10,AT&T 贝尔实验室,1990 年 11 月.

David M. Gay: "Correctly rounded binary-decimal and decimal-binary conversions." Technical Report 90-10, AT&T Bell Laboratories, November 1990.

一些相关的后续工作:

Robert G. Burger 和 R. Kent Dybvig:快速准确地打印浮点数."ACM SIGPLAN 1996 编程语言设计与实现会议,美国宾夕法尼亚州费城,1996 年 5 月,第 108-116 页

Robert G. Burger and R. Kent Dybvig: "Printing floating-point numbers quickly and accurately." In proceedings of ACM SIGPLAN 1996 conference on Programming Language Design and Implementation, Philadelphia, PA, USA, May 1996, pp. 108-116

Guy L. Steele Jr. 和 Jon L. White:回顾:如何准确打印浮点数."ACM SIGPLAN 通知,卷.39, No. 4, April 2004, pp. 372–389

Guy L. Steele Jr. and Jon L. White: "Retrospective: How to print floating-point numbers accurately." ACM SIGPLAN Notices, Vol. 39, No. 4, April 2004, pp. 372–389

Florian Loitsch:使用整数快速准确地打印浮点数."2010 ACM SIGPLAN 编程语言设计与实现会议,加拿大安大略省多伦多,2010 年 6 月,第 233-243 页

Florian Loitsch: "Printing floating-point numbers quickly and accurately with integers." In proceedings of 2010 ACM SIGPLAN Conference on Programming Language Design and Implementation, Toronto, ON, Canada, June 2010, pp. 233-243

Marc Andrysco、Ranjit Jhala 和 Sorin Lerner:打印浮点数:一种更快、始终正确的方法."ACM SIGPLAN 通知,卷.51,第 1 期,2016 年 1 月,第 555-567 页

Marc Andrysco, Ranjit Jhala, and Sorin Lerner: "Printing floating-point numbers: a faster, always correct method." ACM SIGPLAN Notices, Vol. 51, No. 1, January 2016, pp. 555-567

Ulf Adams:Ryū:快速浮点到字符串的转换."ACM SIGPLAN 通知,卷.53,第 4 期,2018 年 4 月,第 270-282 页

Ulf Adams: "Ryū: fast float-to-string conversion." ACM SIGPLAN Notices, Vol. 53, No. 4, April 2018, pp. 270-282

这篇关于将 IEEE 754 double 转换为字符串的算法?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆