Yes, it's a static cast, so llvm should optimise that out. Do note however that the API has changed in 0.9-pre, and num::cast now returns an Option<T>. So your code would be:
~~~ let res: T = aVariable / num::cast(2).unwrap(); ~~~ LLVM should resolve the conditional at statically - I haven't checked though. ~Brendan On 28/10/2013, at 8:26 PM, Rémi Fontan <[email protected]> wrote: > Hi, > > just checking performance wise, is num::cast() doing a dynamic type cast or a > static cast. > > I'm writing some template code that works on Real and I need sometime to > divide T:Real by 2 or compate with 0 or 1. > > I've been using num::zero() and num::one() so far but how about dividing by 2? > > should I write something like this: > > let two = num::one::<T>()+ num::one::<T>(); > let res:T = aVariable / two; > > or would be just as efficient? > let res:T = aVariable / num::cast::<float, T>(2.0); > > or is there an even better alternative? > > with rust 0.8. > > cheers, > > Rémi > > -- > Rémi Fontan : [email protected] > mobile: +64 21 855 351 > 93 Otaki Street, Miramar 6022 > Wellington, New Zealand > _______________________________________________ > Rust-dev mailing list > [email protected] > https://mail.mozilla.org/listinfo/rust-dev
_______________________________________________ Rust-dev mailing list [email protected] https://mail.mozilla.org/listinfo/rust-dev
