matterhorn103 / quanstants

Intuitive and unastonishing physical quantities, units, constants, and uncertainties in Python
MIT License
0 stars 0 forks source link

Change rounding defaults #11

Closed matterhorn103 closed 2 months ago

matterhorn103 commented 2 months ago

At the moment, numbers can be reported with up to 28 digits.

Firstly, this makes things a little unreadable.

More importantly, this often makes little sense, for example if the size of the uncertainty means that actually the number is only correct to e.g. 5 decimal places.

Need to consider what a sensible precision to return is when __repr__ and __str__ are called, and how it should be shown to the user that the number is known to greater precision than that printed -- with ... for example?

matterhorn103 commented 2 months ago

Perhaps if a Quantity has an uncertainty, the number should be rounded to the uncertainty for printing. The uncertainty itself should be rounded to 2 s.f. for this by default.

Possibly there should be a config option to turn the automatic rounding off.

On the other hand, this might be annoying as the user would find their deliberate choice of rounding to be overridden by the defaults chosen.

In any case, the unrounded value should be retained, so it would be important that it is somehow communicated to the user that it is only the printed representation that has been rounded. Maybe it should only be for __str__ and not __repr__.

And what should be done with "exact" quantities is another question.

matterhorn103 commented 2 months ago

Decided that this behaviour would be counterintuitive. No other numbers in Python function like this and it would be unexpected behaviour.

Instead, the default rounding behaviour of .round() will be made round to uncertainty so that a sensible precision is easily available for printing, and a config option will be exposed that allows the user to turn on automatic rounding before printing.