[
https://issues.apache.org/jira/browse/THRIFT-5496?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17472290#comment-17472290
]
Richard H. Gumpertz edited comment on THRIFT-5496 at 1/10/22, 8:45 PM:
-----------------------------------------------------------------------
Question (1) was asked because I'm wondering why the code went to such extremes
to avoid using scientific notation. My fix followed that concept but made it
work correctly because I assumed somebody, somewhere, sometime, had a good
reason for adding the extra code needed to do it that way. If there is no
underlying reason for avoiding scientific notation, perhaps a "general"-like
format would make the most sense: fixed notation for numbers with an absolute
value >=.0001 (possibly with a few more 0s after the decimal point) and <1e17
and fixed for all others.
Another possibility if we want to maximize the likelihood that the number would
be read back in matching exactly what the Thrift compiler saw would be to use
HEX floating-point literals instead of decimal (see
[https://en.cppreference.com/w/cpp/language/floating_literal]). The downside,
of course, is that it would require C++17 as the target compiler (we probably
don't want to do that {_}yet{_}) and it would make the numbers unreadable to
({_}most?{_}) humans.
The current code can produce _*totally wrong*_ results, which I think is
unacceptable. I made the smallest change I could think of to avoid that.
Hence, at least for now, I stand by the code that I submitted because it is the
least likely to break anything that I/we don't know about (such as the full
answer to question (1)).
was (Author: JIRAUSER283319):
Question (1) was asked because I'm wondering why the code went to such extremes
to avoid using scientific notation. My fix followed that concept but made it
work correctly because I assumed somebody, somewhere, sometime, had a good
reason for adding the extra code needed to do it that way. If there is no
underlying reason for avoiding scientific notation, perhaps a "general"-like
format would make the most sense: fixed notation for numbers with an absolute
value >=.0001 (possibly with a few more 0s after the decimal point) and <1e17
and fixed for all others.
Another possibility if we want to maximize the likelihood that the number would
be read back in matching exactly what the Thrift compiler saw would be to use
HEX floating-point literals instead of decimal (see
[https://en.cppreference.com/w/cpp/language/floating_literal]). The downside,
of course, is that it would require C++17 as the target compiler (we probably
don't want to do that {_}yet{_}) and it would make the numbers unreadable to
({_}most?{_}) humans.
For now, I stand by the code that I submitted because it is the least likely to
break anything that I/we don't know about (such as the full answer to question
(1)).
> Thrift compiler (C/C++) truncates small doubles to a fixed number of digits
> after the decimal point
> ----------------------------------------------------------------------------------------------------
>
> Key: THRIFT-5496
> URL: https://issues.apache.org/jira/browse/THRIFT-5496
> Project: Thrift
> Issue Type: Bug
> Components: C++ - Compiler
> Affects Versions: 0.15.0
> Reporter: Richard H. Gumpertz
> Priority: Minor
> Original Estimate: 0h
> Time Spent: 10m
> Remaining Estimate: 0h
>
> When the Thrift C++ compiler generates double constants in .h files, it
> (1) doesn't use scientific notation (e.g., 123.45e-22)
> (2) uses a fixed number of digits after the decimal point
> Hence, if the constant to be generated is small but non-zero, it shows up as
> "0.0000000000000000" (17 digits of precision, 16 after the decimal point).
> (1) Would somebody please explain why scientific notation is not used when
> appropriate?
> (2) Assuming that there is a good reason for not using scientific notation, I
> have created a fix that instead generates
> "0.000000000000000000012345000000000000" (17 digits of precision following
> the 19 '0's between the decimal point and the '1'.
> I made this fix in .../generate/t_erl_generator.cc,,
> .../generate/t_generator.cc,, and .../test/DoubleConstantsTest.thrift.
> I will submit a github pull request shortly.
--
This message was sent by Atlassian Jira
(v8.20.1#820001)