tfussell / xlnt

:bar_chart: Cross-platform user-friendly xlsx library for C++11+
Other
1.5k stars 423 forks source link

long double for numeric cells #201

Closed chris-b1 closed 7 years ago

chris-b1 commented 7 years ago

https://github.com/tfussell/xlnt/blob/0ac12101fc8778b38be793968c3231fb5f930f11/source/detail/implementations/cell_impl.hpp#L54

I haven't looked at the actual XML spec, but in practice the max value in excel seems to be based on a double, so thinking this maybe should be changed? https://support.microsoft.com/en-us/help/78113/floating-point-arithmetic-may-give-inaccurate-results-in-excel

May also introduce some some subtle platform differences where MSVC treats long double exactly as a double?

tfussell commented 7 years ago

I have been hesitant to replicate all of Excel's number handling behaviour (which has its own Wikipedia article), but it seems like it's inevitable. This at least shouldn't be too significant of a change so I will think about it.

chris-b1 commented 7 years ago

Thanks, yeah I don't think it's a big deal, just was surprised to see that type. For "fun" here's what seem to be the relevant bit of the spec, I guess defaulting to double, but leaving option for other ranges open.

18.17.5.2 Precision
In order to clarify the semantics of cell formulas and values in SpreadsheetML, it is necessary to specify the
precision of the numbers being represented in the file format. These numbers are therefore regarded as
ranging over a specific value space, which defaults to the following:
The value space consists of the values (-1)^s × m × 2^n, where s is 0 or 1, m is an integer greater than or equal to
0 and less than 2^53, and n is an integer between -1074 and 971, inclusive. m is herein referred to as the binary
mantissa, and n is herein referred to as the binary exponent. [Note: The default precision is patterned after the
IEC double-precision 64-bit floating-point type [IEC 60559]. end note]

Implementing applications can use the characteristics markup (§22.7) to specify other value spaces to replace
the default in a given workbook. When present in the workbook, the value space defined using the
characteristics markup overrides the default value space.
tfussell commented 7 years ago

This is done now. Please comment here if you notice any problems with this change.