[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
bug#47302: 27.1; calc math-format-number formatting for floats without d
From: |
Mattias Engdegård |
Subject: |
bug#47302: 27.1; calc math-format-number formatting for floats without decimals is unusual |
Date: |
Sun, 25 Apr 2021 17:53:30 +0200 |
22 apr. 2021 kl. 18.35 skrev Dave Gillespie <Daveg@synaptics.com>:
> 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?
calc-digit-after-point.diff
Description: Binary data