Skip to content

Correct fns exp2 that were calling exp #22076

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

Merged
merged 1 commit into from
Feb 11, 2015
Merged

Correct fns exp2 that were calling exp #22076

merged 1 commit into from
Feb 11, 2015

Conversation

carols10cents
Copy link
Member

Fixes #22080.

I was working on adding examples to the documentation in std::num::Float. I got to exp2, which says "Returns 2 raised to the power of the number, 2^(self)."

So I tried running this code:

use std::num::Float;

#[test]
fn test_exp2() {
    assert_eq!(32.0, 5.0.exp2());
}

and it resulted in a failure of (left: 32, right: 148.413159). That 148.413159 is the value for e^5, which is exp(), not exp2().

Sure enough, exp2 is calling exp and shouldn't be, looks like a copy-paste error.

I haven't added any tests for this since it's unlikely to break again, but I will happily do so if people think that would be a good idea. The doc examples are coming :)

I scanned through the other functions in these files for similar sorts of errors and didn't notice any.

@rust-highfive
Copy link
Contributor

r? @aturon

(rust_highfive has picked a reviewer for you, use r? to override)

@huonw
Copy link
Member

huonw commented Feb 8, 2015

Nice catch! It seem like all of these functions should have some basic tests to protect against issues like this, a few have such tests (e.g. asinh) but there's a lot missing. Could you add one for exp2 testing a handful of numbers (e.g. extremes like INFINITY, NEG_INFINITY, 0 and one or two "general" values)?

If you're feeling energetic it would be great to add some tests for some of the other functions, but this is definitely not necessary in this patch.

@huonw huonw assigned huonw and unassigned aturon Feb 8, 2015
@nagisa nagisa mentioned this pull request Feb 8, 2015
@carols10cents
Copy link
Member Author

@huonw I've added some tests for exp and exp2, I'll probably add tests for the others in another PR. Thank you!!!! 🌻

@mdinger
Copy link
Contributor

mdinger commented Feb 8, 2015

Ug. See #22030 which is documenting float. Sounds like you're working on the same thing. Probably don't want to be duplicating each others work...Maybe we should check to see if one has better examples...

@carols10cents
Copy link
Member Author

@mdinger I didn't get too far with the documentation, I stopped when I hit this bug, so you've got better examples for the docs. It's so funny that we both found this within hours!!!

@mdinger
Copy link
Contributor

mdinger commented Feb 8, 2015

Agreed. FYI, I'm working from the top down so if you decide to submit a PR against it, start at the bottom and work up. I typically only do a few examples day so it may take a few more days to finish. Then I have to test it.

@huonw
Copy link
Member

huonw commented Feb 11, 2015

@bors r+ 8379

Thanks

@bors
Copy link
Collaborator

bors commented Feb 11, 2015

⌛ Testing commit 8379062 with merge 5936278...

bors added a commit that referenced this pull request Feb 11, 2015
I was working on adding examples to the documentation in `std::num::Float`. I got to `exp2`, which says "Returns 2 raised to the power of the number, `2^(self)`."

So I tried running this code:

```
use std::num::Float;

#[test]
fn test_exp2() {
    assert_eq!(32.0, 5.0.exp2());
}
```

and it resulted in a failure of `(left: `32`, right: `148.413159`)`. That 148.413159 is the value for e^5, which is `exp()`, not `exp2()`.

Sure enough, `exp2` is calling `exp` and shouldn't be, looks like a copy-paste error. 

I haven't added any tests for this since it's unlikely to break again, but I will happily do so if people think that would be a good idea. The doc examples are coming :)

I scanned through the other functions in these files for similar sorts of errors and didn't notice any.
@bors bors merged commit 8379062 into rust-lang:master Feb 11, 2015
@carols10cents carols10cents deleted the exp2-calling-exp branch February 14, 2015 22:08
bors added a commit that referenced this pull request Mar 8, 2015
Building on #22076, I've added some tests for stable methods in f32 and f64 that didn't have any before.

Please let me know if there are any improvements I can make, and I am happy to make them! 📬
Manishearth added a commit to Manishearth/rust that referenced this pull request Mar 8, 2015
 Building on rust-lang#22076, I've added some tests for stable methods in f32 and f64 that didn't have any before.

Please let me know if there are any improvements I can make, and I am happy to make them! 📬
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

Successfully merging this pull request may close these issues.

Float::exp2() is calling exp()
6 participants