-
Notifications
You must be signed in to change notification settings - Fork 382
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
Decomposed the rounded expressions in the unit definitions into operations with exact coefficients #1393
base: master
Are you sure you want to change the base?
Conversation
…tions with exact coefficients.
…density of water (1000 kg/m3)
I wasn't able validate the conversion expressions for Pressure head - from what I've read it seems like it involves an additional parameter (density / specific weight): I haven't checked, but if I were to try to decompose the expression in The same goes for the |
For Luminosity 3.828x10^26 would be the correct one since it comes from NASA. |
I also think that for v6 we should replace the Here's what I have in mind:
There is unfortunately no way to make the conversion exact:
|
I would also suggest that for the PS |
I also have an issue with the following two "units":
I was going to suggest replacement functions for constructing with / converting to a number (e.g. Frequency.FromBUnit(..)) but I fail to find any information online about either of these units, so I wonder if those methods are actually useful.. @bplett-wgtcorp Are you still relying on these units? Do you think there are still active applications that depend on them? |
I'm still not 100% that either of the values is correct but I am pretty confident that they can't both be right: Assuming that Fixing it would most certainly break a test... |
"FromUnitToBaseFunc": "{x} / 6.852176556196105e-2", | ||
"FromBaseToUnitFunc": "{x} * 6.852176556196105e-2", | ||
"XmlDocSummary": "The slug (abbreviation slug) is a unit of mass that is accelerated by 1 ft/s² when a force of one pound (lbf) is exerted on it.", | ||
"XmlDocRemarks": "http://en.wikipedia.org/wiki/Slug_(unit)", | ||
"FromUnitToBaseFunc": "{x} * (32.17405 * 0.45359237)", | ||
"FromBaseToUnitFunc": "{x} / (32.17405 * 0.45359237)", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think I finally figured out the Slug
- the coefficient in the referenced wiki page for (slug -> lb) : 32.17404
is in fact not an exact value, but should be given the expression 9.80665 / 0.3048
which evaluates to ~32.174048556430446194225721784777
.
There is in fact a second article which first states that
the standard acceleration due to gravity, approximately 32.174049 ft/s2 (9.80665 m/s2)
but then finishes by:
This definition can be rephrased in terms of the slug. A slug has a mass of 32.174049 lb.
I'm no expert, but here's what I could find in the NIST publication from 2008 (Page 53):
22 The exact conversion factor is 4.535 923 7 E−01. All units in Secs. B.8 and B.9 that contain the pound refer to the avoirdupois
pound.
23 The exact conversion factor is 4.448 221 615 260 5 E+00 since the standard value of the acceleration due to gravity,
gn = 9.806 65 m/s 2 exactly, is used to define the kilogram-force: 1 kgf = 9.806 65 E+00 N exactly
From this I can deduce that the expression for the Impulse
for both PoundForceSecond
and SlugFootPerSecond
should be {x} * 0.45359237 * 9.80665
.
The same replacement should be done for Density
and MassConcentration
where the Slug
is being referenced, but given how inaccurate the approximation was, I'm not going to bother doing it for v5 as it looks likely to break more tests..
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great effort, I love how you dig into the details of this 👏
Let me know if there is anything I can help with.
As for the above questions about removing problematic units, I'd prefer to not remove anything just for the reason that it does not fit the new exact conversion implementation. I'd rather add special cases for units that do things like Math.Sqrt
, Math.Sin()
and have them work like today.
If we however find units that are plain wrong or reasonably proven not in use, we can discuss removing those.
Motivation
Many of the expressions used in the UnitDefnitions (json files) currently correspond to the result of the division of two numbers that do not produce a terminating decimal: see how in #1389 the conversion for
VolumeFlow
for UkGallonsPerHour) is given as791887.667
.There are of course many cases where the resulting decimal is simply rounded, or is the result of some online converter that is introducing similar rounding errors (I don't know any that operate using rational numbers).
What is worse is that the AI agents are also picking up on these incorrect results, sometimes referencing this library.
Working with the
double
type, up until now, these rounding errors were not very important- however as per my upcoming proposal for v6 (incorporating theFractions
as the underlying value type), there wouldn't be any rounding errors.Approach
I've taken the following approach when working through the list:
Mass
/Length
etc - look at every coefficient, and the corresponding Wikipedia page- find where it saysexactly equal to ...
and take that (putting the corresponding link in the xml-docs).1/16 of something-else
I useexpression-for-something-else / 16
, where theexpression-for-something-else
is either acoefficient
or anotherexpression
.Area
then toVolume
etc., working in the exact same way- takingcoefficients
orexpressions
that are eitherexactly equal to ...
or (more often) referencing one of the previously verified filesResult
This resulted in almost half of all quantities receiving some modification to their expressions. Most of these are related to conversions involving the US/British units but there is also some confusion regarding the Calorie - the value of
4.1868
was used (instead of4.184
) in a few places, which is a note-worthy difference.Here are all the tests that broke:
HeatFlux
: due to the change inCalorie
HeatTransferCoefficient
: due to the change inCalorie
Impulse
:PoundFootPerSecond
,SlugFootPerSecond
were represented by a single coefficient that is significantly different from what got: I've used the expression for thePoundal
:{x} * (0.45359237 * 0.3048)
(0.138254954376) instead of{x} / 7.230657989877
(0.13830000000000150747000000001643)- although seeing how close this is to 0.1383 there might be something I'm missing here...Luminosity
: there are two conflicting values for the coefficient online- the top result on google points to this page (where the original value was taken from), while the linked article on Wikipedia (as well as the article about the Sun) both have it listed as 3.828×1026 W[5]. This was added in Added units for Astronomy. #680 by @ebfortin - hopefully he could confirm which one is the correct value.Power
: MechanicalHorsepower changed from{x} * 745.69
to{x} * 76.0402249 * 9.80665
as given by this articlePressure
the TechnicalAtmosphere coefficient (no idea where the old one was taken from)SpecificFuelConsumption
: I'm not a domain expert, but{x} * 28.33
doesn't look right forPoundMassPerPoundForceHour
(lb/(lbf·h))- here's what I got:{x} * 453.59237 / (0.0044482216152605 * 3600)
ThermalResistance
: using different conversion coefficients forBTU
andCalorie
from the one defined inEnergy
(note: I wasn't able to confirm the "correct" conversion coefficient for BTU).VolumetricHeatCapacity
: using different conversion coefficient forCalorie