Skip to content
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

Incorrect meters to km #42

Open
lazaronixon opened this issue Jun 30, 2018 · 1 comment
Open

Incorrect meters to km #42

lazaronixon opened this issue Jun 30, 2018 · 1 comment

Comments

@lazaronixon
Copy link

1000.meters.to.kilometers is returning 1000. it should be 1

@halogenandtoast
Copy link
Owner

Howdy,

I think the issue here is that it's not clear what Measurement#to_f is doing, in this case, but to get the correct value you should be using Measurement#value here instead:

1000.meters.to.kilometers.value # => 1

The way switching between prefixes like kilo is by storing the information like this:

#<Alchemist::Measurement:0x00007fe57a2117d8 @value=1.0, @unit_name=:meters, @exponent=1000.0>

The idea at the time was that kilometers and meters are conceptually the same measurement just with an exponent, so calling Alchemist#to_f gives you the following:

def to_f
  (precise_value * exponent).to_f
end

Which describes it in terms of the base meters, instead of kilometers. I think I agree that this can be confusing so my plan is to resolve this for the "eventual" 1.0 release.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants