-
Notifications
You must be signed in to change notification settings - Fork 77
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Implement concept of precision #1
Comments
See NIST SP 1038, section 4.4.1 on the topic of precision and rounding: |
I don't know if this is quite the same thing, but there is also the concept of context-specific precision. For example, if you have a person's height in feet and inches, it will generally be measured to the nearest inch (half-inch, perhaps, for children). When converting to cm you probably want a number that is a whole number of cm, not a precise calculation to many decimal places. If it were possible to specify the precision of a measurement, (e.g. |
Any news on this? I just found out that converting from one unit of measure to anotehr (in my case kg to lbs) and then casting to string the result prints a huge number. It would be really really useful to be able to specify at least the amount of digits to display. The code that I use is below: $length = new Mass($value, 'kg');
$convertedLength = new Mass($length->toUnit('lbs'), 'lbs');
echo (string) $convertedLength; |
Why don't you use number_format? |
I thought to use it, but unfortunately I don't see any way to extract the numeric value from the EDIT |
This has nothing to do with the original issue, please open a new one if the problem persists. I don't really understand why you want a new instance of Mass but Something like this could work: $a = new Mass(1, 'kg');
//this is a float
var_dump($a->toUnit('lbs'));
echo sprintf('%s %s', number_format($b->toUnit('lbs'), 2), 'lbs'); |
The central issue of this ticket is physical measurement precision and how it relates to the concept of significant figures. For instance, when we say "1 meter", what's the precision of that measurement? is it 1 meter precisely? 1.0 meters? 1.0000000 meters? Currently in this library, there's no way to encode the precision of the measurement when instantiating a physical quantity object. Also, It's important to understand that because this library can also convert between units of measure, choosing the number of digits to show in a value is more complicated than simply "rounding" to one digit or the next. You might have a situation after a conversion where leaving off a digit is giving up real knowledge of the measured value, but including that digit is rolling in some false knowledge that implies precision that isn't real. In scientific measurement, ultimately, this ends up being a judgement call on the part of the user. This is bound up in the concept of error propagation and false precision. I recognize that for most folks this is all tedious and irrelevant, but it was an identified goal at the start of the project, and so this ticket remains focused on this issue. For the more practical discussion earlier in this ticket regarding display formatting of values, I'd invite you to open a new issue. However, my position is likely to be similar to what @soyuka suggested, as I believe that adding string-formatting features may be outside the scope of this library. |
Currently, the transform functions don't have any regard for significant digits and proper error calculation.
This is a complicated issue. Some conversions are defined as having infinite precision; for instance the inch is defined to be precisely 0.3048 meters, and so can be treated as being infinitely precise. In contrast, a furlong is stated on wikipedia as being approximately 201.168 meters, but that is not the exact definition of a furlong, and thus the precision is limited to 6 significant figures.
Figure out the best way to represent the error in these transformations, and make sure that the conversions respect the proper treatment of significant digits and precision.
The text was updated successfully, but these errors were encountered: