我正在尝试学习如何使用 Microsoft 的 Open XML SDK。我按照他们关于如何使用 a 创建 Word 文档的步骤进行操作FileStream,效果非常好。现在我想创建一个Word文档,但仅在内存中,并等待用户指定是否要保存该文件。
Microsoft 的这份文档说明了如何使用 处理内存中的文档MemoryStream,但是,该文档首先从现有文件加载并“转储”到MemorySteam. 我想要的是完全在内存中创建文档(而不是基于驱动器中的文件)。我认为可以实现这一点的是这段代码:
// This is almost the same as Microsoft's code except I don't
// dump any files into the MemoryStream
using (var mem = new MemoryStream())
{
using (var doc = WordprocessingDocument.Create(mem, WordprocessingDocumentType.Document, true))
{
doc.AddMainDocumentPart().Document = new Document();
var body = doc.MainDocumentPart.Document.AppendChild(new Body());
var paragraph = body.AppendChild(new Paragraph());
var run = paragraph.AppendChild(new Run());
run.AppendChild(new Text("Hello docx"));
using (var file …Run Code Online (Sandbox Code Playgroud) 我一直在阅读,似乎 IEEE 754 将 64 位浮点数(双)指数定义为 11 位。( https://en.wikipedia.org/wiki/Double-precision_floating-point_format )
我的问题是为什么?
64 位浮点数有 53 位有效数(第一位暗示为 1,因此实际仅存储 52 位)-因此您需要指数至少能够表示数字 53(以便能够移动二进制基数指向有效数中的任何位置),因此现在您需要 7 位。
然后你还需要负指数,所以 8 位。
此外,您还需要表示 0、负无穷大和正无穷大以及 NaN-(需要 4 个额外的表示),所以我猜是 10 位。
所以我的问题是:为什么指数是 11 位而不是 10 或 12 位,以及如何确定其他长度的浮点数?