Repository navigation
Conversation
Excel 16.116 for Mac shows none of a subnormal number's digits, in TEXT and in a cell alike. Under 0.000E+000 it writes: - 0.000E-001 for a positive one from 2^-1026 up - 0.000E+000 for a positive one below 2^-1026, as for 0 - -0.000E-001 for a negative one Apply this to every pattern with at most one integer digit. Only 0.000E+000 was checked, so the other patterns are an assumption. Leave engineering patterns alone: an exponent of -1 is not a multiple of their digit count. Two existing tests pinned the digits of a subnormal number. The first now expects Excel's text; the second moves to engineering patterns, which still go through the shortest representation.
Excel 16.116 for Mac shows every subnormal number under General as 0 in a cell, and a negative one as -0. TEXT(x,"General") reads 0 for EXP(-710) and EXP(-744.44); a negative value under TEXT was not checked, and is written as in a cell. This keeps a subnormal number's own exponent out of General, and updates the one existing test that pinned 2.33E-321.
The rule's boundary is one integer digit, and no test had a pattern with two: changing it to admit them passed. Add one, and a thousands-scaled pattern next to the percent one.
Only 0.000E+000;(0.000E+000) had a test. Cover a literal minus in the second section, a third section, and General sections; their text under the base commit shows the digits. A normal number under the same pattern is the control.
Say what the code does rather than what was not checked, and name tests by behavior rather than by "unchanged". Split out the largest subnormal, which is an assumption about values, from the test of assumed patterns.
Excel ignores the scaling there, in TEXT and in a cell, on Mac and Windows: - 0.000E+000% of -0.4 is -4.000E-001%, where numfmt wrote -4.000E+001% - 0.000E+000, of -0.4 is -4.000E-001, where numfmt wrote -4.000E-004 - TEXT(1E-300,"0.000E+000%") is 1.000E-300%, where numfmt rounded the scaled value to 0 and wrote 0.000E+000% A subnormal number under such a pattern therefore follows the unscaled rule.
Excel for Mac and for Windows give such a number the zero section of a three-section pattern, so 0.000E+000;(0.000E+000);"zero" of EXP(-720) is zero, and the text for 0 under engineering patterns: ##0.0E+0 of it is 000.0E+0, and TEXT(0,"##0.0E+0") is the same. Choosing it as 0 before the section covers all of these, and colors too. Engineering patterns no longer reach the shortest-representation path for such a number, so test that path through roundSignificand.
Excel for Mac and for Windows write a zero significand under engineering patterns too, with the exponent that the pattern gives 0.4: ##0.0E+0 of 2^-1023 is 000.0E-3, and #0.0E+0 is 00.0E-2. A pattern with no integer digit writes 0: .000E+000 of 2^-1023 is .000E+000, and -0.4 under it is -.400E+000. This replaces the assumption that only patterns of at most one integer digit change, and that their exponent is always -1.
TEXT(x,"General") is 0 for every subnormal number, negative too, in Excel for Mac and for Windows; a cell under General shows a negative one as -0. numfmt has one output and format() returns text, so follow TEXT. Cell and TEXT agree on the rest: General;(General) of a negative subnormal is 0, without the parentheses, and "x"General is x0. So it is formatted as 0, in the section for 0. @ reads the same under TEXT.
Excel for Mac and for Windows read # ?/? of a subnormal number as 0 followed by four spaces, with a minus if it is negative, where numfmt wrote " 1/1" and "- 1/1".
Replace test names that called these patterns unchecked, and cover the other patterns, sections and date fallback as read in Excel for Mac and for Windows. numfmt's date fallback for a negative number stays: yyyy-mm-dd of a negative subnormal keeps following its options, where TEXT is #VALUE!.
Excel gives a positive number below 2^-1026 the section for 0, but does not format it as 0 in every pattern: ?/? of EXP(-720) is 1/1, and of 0 is 0/1, where numfmt wrote 0/1 for both. A negative or larger one reads 1/1 or -1/1 there too, so a fraction pattern writes the text for 0 only if it has integer digits. Only the section is chosen as for 0 now; the scientific exponent takes the same test itself.
…section General;(General);"z" of 2^-1023 is 0 in Excel for Mac, where numfmt wrote z; EXP(-720) and its negative are z, as 0 is. So only a negative subnormal number under General takes the section for 0.
Excel for Mac reads [>0]"p";"n" of -0.4 and of a negative subnormal number as n, where numfmt wrote -n, and the same under [>0]0.0E+0;"n". This is the narrowest change that fits: the readings don't separate the condition from the literal section, so other [>=N] conditions and digit second sections keep their minus.
Excel for Mac reads # 0/0 of 0 as 0/1 and of -0.4 as -2/5, where numfmt wrote " 0/1" and "- 2/5". # ?/8 of -0.4 keeps its space, and 1.5 under # 0/0 is written as before.
Excel for Mac reads -0.4 under [>0]0;0.0 as 0.4, [>0]"p";0.0 as 0.4 and [>=0]"p";"n" as n, and under [>=1]"p";"n" as -n, where numfmt wrote -0.4, -0.4, -n and -n. So the literal section was not the cause: the minus goes where the first condition takes in every positive number. That is inferred from conditions at 0 and 1; other thresholds keep what numfmt did. So does the General section implied by [>0]0, which Excel has not been checked on. Also pin the readings at 2^-1026 and -2^-1023 under a condition and General;(General);"z", which numfmt already matched.
Excel for Mac reads ?/8 of 2^-1023 and of -EXP(-720) as 0/8, with no minus, where numfmt wrote blanks and "-" with blanks. ?/? keeps its 1/1 and -1/1. The change writes the fixed denominator for 0 too: ?/8 of 0 reads 0/8, where numfmt wrote 0/1. ?/8 of a normal number that rounds to no eighths still writes blanks, unchecked in Excel.
# 0/? of 0 reads 0/1 in Excel for Mac, where numfmt wrote "0/" and a blank. A subnormal number takes the same path here, and now writes 0/1 or -0/1, as # 0/0 reads for those numbers; Excel has not been checked on them under # 0/?. Also pins # 00/00 of 0 and # 0/? of -0.4, which numfmt already matched.
This reverts ec2b17c, efcc98e and 497032b, which changed normal numbers as much as subnormal ones, so the rule moves to a change of its own. A negative subnormal number under [>0] or [>=0] writes the minus as it did before. Keeps the tests of which section a positive subnormal number takes, and of General;(General);"z" around 2^-1026.
This reverts 4c825c1, which changes normal numbers and 0, so it moves to a change of its own.
This reverts f3ef3e5, which changes normal numbers under 0.000E+000% and 0.000E+000, so it moves to a change of its own. A subnormal number under such a pattern writes what it did before: scaling rounds it to 0, so it has no digits, no minus, and exponent 0.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fix
format()writing a subnormal number's digits where Excel writes none:format('0.000E+000', Math.exp(-720))was2.032E-313where Excel reads0.000E+000, andformat('General', Math.exp(-720))was2.0322E-313where Excel reads0. This covers point 3 of #105.Checked in Excel for Mac and Windows:
Differs from Excel: a cell under General shows a negative subnormal number as
-0(TEXTgives0, as numfmt does). Fractions, scaled scientific formats and the minus under a condition are left as they were, and also differ.Not checked: typed entry, reopened workbooks, other locales.