Comments (4)
Yeah, it is a balancing job between a number of different unit conventions. There are a few programs which specify that .
is a multiplier, other programs or conventions where a space is a multiplier. And in a linguistic sense -
is a connector that bridges two parts of a word or a prefix or modifier. So I am sure there are a few cases where the complex conglomeration of those conventions make the interpretation a bit odd. I suppose some additional consideration of situations that end in a .
might be warranted as that would indicate the .
being used as an abbreviation rather than as a multiplier. If there are specific unit strings that get interpreted incorrectly there are a couple different ways I put in to interpret them and bypass most of the other logic that tries to figure out some sort of meaning from strings and break it into individual components.
from units.
Playing around with this and how to interpret '.' This is what I have currently
// interpret . as multiply
EXPECT_EQ(precise::m * precise::s, unit_from_string("m.s"));
// interpret m as abbreviation so milli
EXPECT_EQ(precise::milli * precise::s, unit_from_string("m. s"));
// interpret as abbreviation so millisecond
EXPECT_EQ(precise::milli * precise::s, unit_from_string("m. s."));
// connector so space = multiply
EXPECT_EQ(precise::m * precise::s, unit_from_string("m- s"));
// connector so space = multiply
EXPECT_EQ(precise::milli * precise::s, unit_from_string("m-s"));
// s is abbreviation so first . is also abbreviation so millisecond
EXPECT_EQ(precise::milli * precise::s, unit_from_string("m.s."));
a.u.
in this context would be interpreted as astronomical unit instead of a*u
basic rule would be any non numerically sensible .
would be interpreted as an abbreviation if at the end or followed by a space, otherwise it could be considered a multiplier. And it must be consistent for the whole unit string. I.e if one .
shows as abbreviation all will.
If any show as an abbreviation they essentially get removed
[change from previous] "m.s." is equivalent to "m. s."
from units.
And it must be consistent for the whole unit string. I.e if one . shows as abbreviation all will.
👍 nice approach, that makes sense!
What about the recommended (by a number of Journals) abbreviation for "arbitrary units": arb. unit
? Does this parse correctly with the suggested change?
from units.
I went through and looked at a few other units that end in "unit" and added some additional string associated with them and a few modifiers as well so "arb. unit" as a well as a few other descriptions of that will get interpreted as arbitrary unit
from units.
Related Issues (20)
- Issues with parsing single-letter prefixes such as for `atto` HOT 7
- CleanUnitString breaks on 0.2 and 0.3 HOT 1
- Strange choice of units in to_string HOT 6
- Your units conversion service seems to be down... HOT 11
- "kg m" is parsed as "kg" HOT 1
- Question about to_string() function HOT 8
- Format arbitrary unit nicely HOT 4
- Degrees celsius get converted to Kelvin in operations HOT 6
- Function to remove a single user defined unit HOT 2
- Try to start a PR for adding support for KPa, MPa, GPa but permission denied HOT 3
- Using to_string for scalars causes crashes HOT 2
- Use of uninitialised memory in unit maps HOT 7
- "Stress testing" units' string parsing HOT 8
- Favoring SI base units in string formatting? HOT 3
- to_string strange output HOT 4
- expression did not evaluate to a constant HOT 4
- Unary negation of measurements HOT 1
- Please consider to use the googletest package instead of requiring the googletest source tree
- Question: How to install units as a vendored library
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from units.