[rust-dev] TotalOrd and cmp::max

Huon Wilson dbau.pp at gmail.com
Sat Apr 5 01:34:16 PDT 2014


Floating point numbers don't have a total ordering (all of these are 
false: NaN < NaN, NaN == NaN, NaN > NaN).

Use the floating-point specific method, `self.a.max(self.b)`.


Huon

On 05/04/14 19:30, Rémi Fontan wrote:
> Hi,
>
> when compiling following code with rust 0.10 I get following error:
>
> use std::cmp;
> struct vec2d { a:f32, b:f32 }
> impl vec2d {
>     pub fn max(&self) -> f32 {
>         cmp::max(self.a, self.b)
>     }
> }
>
> test.rs:6:9: 6:17 error: failed to find an implementation of trait 
> std::cmp::TotalOrd for f32
> test.rs:6 <http://test.rs:6>         cmp::max(self.a, self.b)
> ^~~~~~~~
> make: *** [test-test] Error 101
>
>
> have I missed something?
>
>
> cheers,
>
> Rémi
>
>
> -- 
> Rémi Fontan : remifontan at yahoo.fr <mailto:remifontan at yahoo.fr>
> mobile: +64 21 855 351
> 93 Otaki Street, Miramar 6022
> Wellington, New Zealand
>
>
> _______________________________________________
> Rust-dev mailing list
> Rust-dev at mozilla.org
> https://mail.mozilla.org/listinfo/rust-dev

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.mozilla.org/pipermail/rust-dev/attachments/20140405/46974824/attachment.html>


More information about the Rust-dev mailing list