Wendelstein7 / DiscordUnitCorrector

A fully functional public Discord bot that automatically corrects non-SI units (imperial, etc) to SI-ones (metric, etc)
Other
11 stars 9 forks source link

Input-dependant significant amount of digits. #23

Open Wendelstein7 opened 3 years ago

Wendelstein7 commented 3 years ago

Different input prompts may find different amount of significant digits relevant. A measurement of whole feet typically doesn't need up to three significant digits. While 3 feet gets corrected to 0.914 m, perhaps 0.9 m or 0.91 m would suffice.

Perhaps the significance of the input could be taken into account: prompt 3.00 feet or 12.54 stone would result in more significant digits than 3 feet and 12 stone would.

Randall-Scharpf commented 3 years ago

Since we're actually considering significant figures, it seems like a good time to mention that the roundsignificant function is actually broken -- whenever it should result in trailing zeroes, it does not provide these zeroes. For example, if I wanted to take a value of exactly 8 and express it with three significant digits, I would have 8.00. However, the roundsignificant function would fail to provide these trailing zeroes and instead just give 8.

Leaving the option flag set to the default of SIGNIFICANTFIGURES = 3 I can demonstrate this behavior: image image image

The same issue exists for large numbers: image image image

Further complicating the issue is the following case: image

It seems that the roundsignificant function only works in a certain, relatively narrow range of cases, and that its shortcomings simply are not typically observed because of the context in which the function is called. Just wanted to make sure you were aware, since fixing the main problem requires fixing the behavior of this roundsignificant function.

Randall-Scharpf commented 3 years ago

I have some partially-functional code for this feature in a fork. I believe it works for almost all cases, however, I would like this to be tested. I've already uncovered the following issues/limitations during my debugging:

Cheers!

Randall-Scharpf commented 3 years ago

I have created a pull request and I believe this fix causes the generator to give the correct number of significant figures for every input, however, third-party verification is always appreciated. If this is in fact true, I would like to request that it be merged. Thanks!