units-of-measurement

F# operator overloading for conversion of multiple different units of measure

三世轮回 提交于 2019-11-30 01:51:33
问题 I want to be able to do this: let duration = 1<hours> + 2<minutes> + 3<seconds> with the following types and functions (and possibly more units of measure): type [<Measure>] seconds type [<Measure>] minutes type [<Measure>] hours let seconds_per_minute = 60<seconds> / 1<minutes> let minutes_per_hour = 60<minutes> / 1<hours> let minutes_to_seconds minutes seconds = minutes * seconds_per_minute + seconds let hours_to_minutes hours minutes = hours * minutes_per_hour + minutes So basically "hours

How is an em calculated?

旧城冷巷雨未停 提交于 2019-11-29 17:24:33
问题 I have noticed that you can use 1em and it will look different on different sites. What is an em in proportion to? The font used? The biggest font size? The page width/height? 回答1: See http://w3schools.com/cssref/css_units.asp 1em is equal to the current font size. 2em means 2 times the size of the current font. E.g., if an element is displayed with a font of 12 pt, then '2em' is 24 pt. The 'em' is a very useful unit in CSS, since it can adapt automatically to the font that the reader uses An

Is there any available API to represent various units of item like KG, Litre, Metre, KM, etc

|▌冷眼眸甩不掉的悲伤 提交于 2019-11-29 17:12:27
问题 In my project, somewhere I have to work with a unitOfIssue of Items . Now, various items of course can have different units of representation. So, I was searching for some API or some way, to elegantly handle this situation. Is there any available API, that provides some way to represent these units? I've heard of JScience which seems impressive, but again I am facing another problem with mapping it in JPA . After some google work, I found out that some work is going on in this context as -

When specifying a 0 value in CSS, should I explicitly mark the units or omit?

▼魔方 西西 提交于 2019-11-29 02:49:12
This is more of a 'philosophy' argument, but I'd like to know what the recommended practice here. I'm not setting it up as a Wiki yet in case there is an 'official' answer. Obviously, there is no difference between 0px and 0em or whatever, so one could simply specify 0 and the units are redundant (see CSS difference between 0 and 0em ). Some of the folks who answered that question argued that one should always omit the units. However, it seems to me that omitting the unit is more error-prone, since a later change may accidentally omit the unit. It is also less consistent with non-zero elements

How do F# units of measure work?

风流意气都作罢 提交于 2019-11-28 20:38:22
Has anyone had a chance to dig into how F# Units of Measure work? Is it just type-based chicanery, or are there CLR types hiding underneath that could (potentially) be used from other .net languages? Will it work for any numerical unit, or is it limited to floating point values (which is what all the examples use)? According to a response on the next related blog post, they are a purely static mechanism in the F# compiler. So there is no CLR representation of the units data. Its not entirely clear whether it currently works with non-float types, but from the perspective of the type system it

Convert letter-tracking value set in Photoshop to equivalent letter-spacing in CSS

你。 提交于 2019-11-28 20:37:05
问题 I am currently building a site from a PSD. Most of the fonts have a letter-tracking of -25 ( <- AV-> : I'm guessing that is the symbol for letter spacing?). How would I get the same effect in CSS? I know the property is letter-spacing: X but it doesn't take percentages and -25px or pts would be a huge figure! 回答1: You can use the em dimension instead of px , thus sizing the spacing relative to the font size (so photoshop's 25% is somewhere around .25em ). 回答2: In Photoshop letter-spacing is

Converting units in R

醉酒当歌 提交于 2019-11-28 20:07:00
I would like to convert from imperial units to metric and vice versa in R. How do I go about doing that? If there is no current way of doing that, how can I create a package that would? I know this is very late, but the package measurements has a function conv_unit() that may be what you're looking for. You enter the imperial value you have, what unit you're converting from (e.g. 'ft') and what you want to convert to (e.g. 'km'). It has a variety of different dimensions (not just length). The nature of the units may affect the presence or absence. In general I think, unfortunately, that @gsk3

Converting bytes to megabytes

旧街凉风 提交于 2019-11-28 15:29:59
I've seen three ways of doing conversion from bytes to megabytes: megabytes=bytes/1000000 megabytes=bytes/1024/1024 megabytes=bytes/1024/1000 Ok, I think #3 is totally wrong but I have seen it. I think #2 is right, but I am looking for some respected authority (like W3C, ISO, NIST, etc) to clarify which megabyte is a true megabyte. Can anyone cite a source that explicitly explains how this calculation is done? Bonus question: if #2 is a megabyte what are #1 and #3 called? BTW: Hard drive manufacturers don't count as authorities on this one! Andrey Traditionally by megabyte we mean your second

preferred mechanism to attach a type to a scalar?

半城伤御伤魂 提交于 2019-11-28 14:31:32
[ edit: changed meters/yards to foo/bar; this isn't about converting meters to yards. ] What's the best way to attach a type to a scalar such as a double ? The typical use-case is units-of-measure (but I'm not looking for an actual implementation, boost has one ). This would appear to be a simple as: template <typename T> struct Double final { typedef T type; double value; }; namespace tags { struct foo final {}; struct bar final {}; } constexpr double FOOS_TO_BARS_ = 3.141592654; inline Double<tags::bar> to_bars(const Double<tags::foo>& foos) { return Double<tags::bar> { foos.value * FOOS_TO

F# Units of measure - 'lifting' values to float<something>

微笑、不失礼 提交于 2019-11-28 12:42:09
When importing numbers from a csv file, I need to convert them to floats with unit. Currently I do this with an inline function: data |> List.map float |> List.map (fun n -> n * 1.0<m>) But I'm wondering if there is a more elegant way to do this - or do I have to create my own 'units' module with conversion functions? What would be really nice would be something like this, but I doubt it's possible... data |> List.map float |> List.map lift<m> This is the opposite of my previous question ( How to generically remove F# Units of measure ). UPDATE: For homemade units, I've tried this, which works