-
Notifications
You must be signed in to change notification settings - Fork 1
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
have float factory take an optional :precision value #261
Comments
@jcredding do you remember why I put this issue in? I can't right now and stupidly didn't put any context into the issue or my dev notes. I have something working for this but am not in love with it. Also, these are floating point numbers so exact values are a lie. Just b/c a value is My implementation looks like this: Factory.float(13) #=> 12.6381341843036762
Factory.float(13, :precision => 2) #=> 10.12
Factory.float(:precision => 2) #=> 95.79 I don't love the method signature but I have to account for both optionally passing a max value and optionally passing a precision value. Couple that with the float values are a lie bit above and I'm ver lukewarm on this (unless we have a good use-case for this). Thanks for any help context. |
@jcredding also the implementation looks something like this: sprintf("%0.#{opts[:precision] || 16}f", (max || 100) * rand).to_f (16 is the default precision used by |
@kellyredding - I'm fine with adding this though I don't know of a good reason we'd need it currently. Maybe with As far as the implementation, I would have done the integer trick where you multiple it by 10^precision, convert to an integer, then divide by the 10^precision but that's more because I forget about |
@jcredding I think I'm going to hold off on this for now. I just don't feel good adding it w/o a good use case. I'll keep this issue around with our notes for future reference if a use case does come up though. Cool? |
(notes from last time I played with this) def self.float(*args)
opts, max = [
args.last.kind_of?(::Hash) ? args.pop : {},
args.last
]
sprintf("%0.#{opts[:precision] || 16}f", (max || 100) * rand).to_f
end
should "allow passing a precision value using `float`" do
skip "TODO: test precision w/ and w/o max value"
end |
This would allow generating floats with a specific precision.
The text was updated successfully, but these errors were encountered: