Skip to content

Give float some examples #22030

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 18, 2015
Merged

Give float some examples #22030

merged 1 commit into from
Feb 18, 2015

Conversation

mdinger
Copy link
Contributor

@mdinger mdinger commented Feb 7, 2015

Some examples for std::num::Float

This is WIP for making examples for f32. This probably won't pass make tidy and I'm not sure which f32 needs documentation. #22025 shows 2 sets of f32 which seems split between core and std. I'm not sure which should be documented but I started doing a couple from std. Easy to move if that's where they go...

Gotta build it eventually to actually see if the docs actually appear where I think they will or if I'm just disillusioned.

cc @steveklabnik

@rust-highfive
Copy link
Contributor

r? @huonw

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

@mdinger
Copy link
Contributor Author

mdinger commented Feb 7, 2015

r? @steveklabnik

@rust-highfive rust-highfive assigned steveklabnik and unassigned huonw Feb 7, 2015
@@ -75,16 +75,86 @@ mod cmath {

#[stable(feature = "rust1", since = "1.0.0")]
impl Float for f32 {
/// Return `NaN`
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this should be Returns NaN. (with an s and a ‘.’)—the indicative style is recommended over the imperative.

(Same thing for the others below.)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed

#[inline]
fn classify(self) -> FpCategory { num::Float::classify(self) }

/// Returns the mantissa, base 2 exponent, and sign as integers. The original
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Previously didn't specify exponents base (2? 10? 7? e?). I had to figure out which one worked to recover the original number.

@nagisa
Copy link
Member

nagisa commented Feb 7, 2015

You could document the trait itself rather than this specific implementation of it, no?

@mdinger
Copy link
Contributor Author

mdinger commented Feb 7, 2015

I don't mind documenting the trait. I was thinking there weren't any examples of traits being documented directly: Iterator and AsSlice for example though I guess IteratorExt is a trait. I can shift.

@mdinger mdinger force-pushed the f32_examples branch 3 times, most recently from 11cf2bc to cd2c941 Compare February 8, 2015 07:05
@mdinger mdinger changed the title WIP: Give f32 some examples WIP: Give float some examples Feb 8, 2015
@mdinger
Copy link
Contributor Author

mdinger commented Feb 9, 2015

Examples shouldn't break if you add a sign somewhere so prefer assigning to variables before using them:

// Should prefer
let f = 2.0f64;
f.powi(2);

// over
2.0f64.powi(2);

// because
-2.0f64.powi(2);

// gets parsed as
-(2.0f64.powi(2));

// when the desired is
(-2.0f64).powi(2);

// but this works properly
let f = -2.0f64;
f.powi(2);

Note: #22105 ran into this.

@steveklabnik
Copy link
Member

Yes, we usually document the trait, not the specific implementation. This seems good though, thanks! would you mind squashing? r=me after

@mdinger
Copy link
Contributor Author

mdinger commented Feb 10, 2015

Got a few left but sure.

@steveklabnik
Copy link
Member

Do you want me to just wait until you've got more? I assumed this was ready, if not, I'm happy to hold off.

@mdinger
Copy link
Contributor Author

mdinger commented Feb 10, 2015

Yeah. I've got another commit incoming. I'll squash after. I got most everything, maybe skipping deprecated and possibly a few unstable.

I'll change the title from WIP when it's ready.

@steveklabnik
Copy link
Member

Cool, thank you

@mdinger
Copy link
Contributor Author

mdinger commented Feb 10, 2015

@steveklabnik This depends on #22076 merging. It won't pass make check until then.

/// Returns the mantissa, base 2 exponent, and sign as integers, respectively.
/// The original number can be recovered by `sign * mantissa * 2 ^ exponent`.
/// The number is encoded with a scheme documented at
/// [IEEE floating point][IEEE-floating-point].
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How a float is encoded needs a good reference. This link is probably wrong and is mainly so I remember. Reposting so it's not hidden.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Deferred to #22152 . Just referred to the float section of the reference for now.

@mdinger mdinger changed the title WIP: Give float some examples Give float some examples Feb 10, 2015
@mdinger
Copy link
Contributor Author

mdinger commented Feb 10, 2015

@steveklabnik Seems pretty good. Needs #22076 though so gotta wait until that lands. I'll do r= after that merges and make check passes. Ready to commit besides all that though.

@mdinger
Copy link
Contributor Author

mdinger commented Feb 16, 2015

Rebased this commit back to tip. Should be mergeable. Didn't retest.

@steveklabnik
Copy link
Member

@bors: r+ 1a133f3

@steveklabnik
Copy link
Member

no rollup as this is a big diff

@bors
Copy link
Collaborator

bors commented Feb 17, 2015

⌛ Testing commit 1a133f3 with merge b603823...

Manishearth added a commit to Manishearth/rust that referenced this pull request Feb 17, 2015
 Some examples for `std::num::Float`

~~This is WIP for making examples for `f32`. This probably won't pass `make tidy` and I'm not sure which `f32` needs documentation. rust-lang#22025 shows 2 sets of `f32` which seems split between `core` and `std`. I'm not sure which should be documented but I started doing a couple from `std`. Easy to move if that's where they go...~~

~~Gotta build it eventually to actually see if the docs actually appear where I think they will or if I'm just disillusioned.~~

cc @steveklabnik
@bors
Copy link
Collaborator

bors commented Feb 17, 2015

💔 Test failed - auto-win-32-nopt-t

@alexcrichton
Copy link
Member

@bors: retry

@bors
Copy link
Collaborator

bors commented Feb 18, 2015

⌛ Testing commit 1a133f3 with merge 4087e5b...

@bors
Copy link
Collaborator

bors commented Feb 18, 2015

💔 Test failed - auto-win-32-nopt-t

@alexcrichton
Copy link
Member

@bors: retry

@bors
Copy link
Collaborator

bors commented Feb 18, 2015

⌛ Testing commit 1a133f3 with merge 886aca4...

@bors
Copy link
Collaborator

bors commented Feb 18, 2015

💔 Test failed - auto-win-64-nopt-t

@alexcrichton
Copy link
Member

@bors: retry

@bors
Copy link
Collaborator

bors commented Feb 18, 2015

⌛ Testing commit 1a133f3 with merge c34229c...

@bors
Copy link
Collaborator

bors commented Feb 18, 2015

💔 Test failed - auto-linux-64-nopt-t

@alexcrichton
Copy link
Member

@bors: retry

@bors
Copy link
Collaborator

bors commented Feb 18, 2015

⌛ Testing commit 1a133f3 with merge 4b92061...

@bors
Copy link
Collaborator

bors commented Feb 18, 2015

💔 Test failed - auto-linux-64-x-android-t

@alexcrichton
Copy link
Member

@bors: retry

@bors
Copy link
Collaborator

bors commented Feb 18, 2015

⌛ Testing commit 1a133f3 with merge 77988b5...

@bors
Copy link
Collaborator

bors commented Feb 18, 2015

💔 Test failed - auto-linux-64-opt

@huonw huonw merged commit 1a133f3 into rust-lang:master Feb 18, 2015
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.

8 participants