Subject: RE: bug#47302: 27.1; calc math-format-number formatting for floats without decimals is unusual

From: Dave Gillespie <[email-masked]>
Date: Mon, 26 Apr 2021 14:58:12 +0000

Yes, that patch makes sense.  Thanks, and thanks for helping with this old beast!

                                                                -- Dave

-----Original Message-----
From: Mattias Engdegård <[email-masked]> 
Sent: Sunday, April 25, 2021 8:54 AM
To: Dave Gillespie <[email-masked]>
Cc: Jelle Licht <[email-masked]>; Stefan Kangas <[email-masked]>; [email-masked]
Subject: Re: bug#47302: 27.1; calc math-format-number formatting for floats without decimals is unusual

CAUTION: Email originated externally, do not click links or open attachments unless you recognize the sender and know the content is safe.

22 apr. 2021 kl. 18.35 skrev Dave Gillespie <[email-masked]>:

> Wow, it has been a long time since I got any correspondence on Calc!

Good to hear from you, Dave! I just fix the occasional Calc bug now and then.

> Calc has a C language mode ('d C' keystroke, controlled by calc-language).  It is a good point that C mode (and probably others like it) should format integer-valued floats as "123.0" even if the default mode does not.  If we apply Jelle's patch, I suggest making it conditional on calc-language so that it applies only in modes such as C mode.  Or perhaps rework it as a text transformation using calc-language-filter.
>
> You could even create a JSON language mode, but most likely the basic C mode is close enough to serve that purpose.

These are all good suggestions. Most languages permit trailing decimal points; the only common exceptions that I can think of are Haskell, Ada and Swift. Apparently JSON is also one. Tying the float-format display to the C, Pascal (etc) modes seems a bit incongruous as it has nothing to do with the syntax of those languages.

How to display a floating-point number with zero fraction also depends on what the user wants to do with the result, so there is a good argument for letting him or her do the required post-processing. Sometimes '1.' should become '1.0', sometimes '1'. For instance, in a LaTeX document it would depend on how the author wants to represent significant digits. A JSON parser (such as the one in Emacs) will parse '1.0' and '1' differently, as a float or integer respectively.

I wrote the patch below as a possible solution but in the light of the above, perhaps it's not ideal?