at some point, I conveniently used num::one and num::zero to write
expressions in template code.

here's a simple example.

pub fn powerCosHemispherePdfW<T:Clone+Float+num::Zero+num::One>(aNormal:
&Vec3x<T>,
                                                         aDirection:
&Vec3x<T>,
                                                         aPower:T ) -> T
{
    let cosTheta = num::max(num::zero::<T>(), Vec3x::dot(aNormal,
aDirection));

    return (aPower + num::one::<T>()) * num::pow(cosTheta, aPower) *
        (num::cast::<float, T>(0.5) * num::Real::frac_1_pi());
}


I already find using num::zero in that code not ideal regarding to
readability, so renaming additiveIdentity even worse.

it is very possible that the code above could be re-written in a better way
and I would love to find out how.


perhaps there is enough room in rust for both simple traits such as zero
and one, and for more advanced mathematical traits such as additive
identity and multiplicative identity.


Rémi



On Fri, Apr 11, 2014 at 8:57 PM, Yegor Wienski <[email protected]>wrote:

> All of the mathematicians I know won’t bother to read them this way (if
> there’s no ambiguity, of course). Long names can be good in scientific
> papers, but in practice one should be a complete boring jerk to name them
> like this.
> It would be a pain typing even the word ‘identity’ in a game engine over
> and over. I write for Unity3d, and Vector3.zero and Vector3.one are just
> fine, but Quaternion.identity makes code look too verbose, so I `static
> readonly QI = Quaternion.identity` it.
> Long names require special training to get comfortable with them, and
> sometimes it even looks like a superpower to me.
>
>
> On 10 Apr 2014, at 19:07, Tommi <[email protected]> wrote:
>
> Actually, I'd like to reiterate my original view that num::Zero should be
> renamed to AdditiveIdentity (bear with me) based on the fact that when
> mathematicians use the symbol 0 to denote additive identity, the symbol 0
> is not read "zero", but as "additive identity".
>
> All the reasoning above applies to renaming num::One to
> MultiplicativeIdentity as well (as it pertains to symbol 1 denoting
> multiplicative identity).
>
> If those names are too long, the shortened AddIdentity and MulIdentity
> could be used instead.
>
>
> On 10 Apr 2014, at 00:06, Tommi Tissari <[email protected]> wrote:
>
> On 09 Apr 2014, at 23:42, Kevin Ballard <[email protected]> wrote:
>
> The number 0 is the additive identity for numbers. But informally, the
> additive identity for other things can be called "zero" without problem.
>
>
> Ok, so it seems. From
> http://en.m.wikipedia.org/wiki/Identity_(mathematics)
>
> The number *0* is the *additive identity* (identity element for the
> binary operation of addition) for integers, real numbers, and complex
> numbers. For every number *a*, including 0 itself,
> [image: 0 + a = a+0=a\,.]
> In a more general context, when a binary operation is denoted with + and
> has an identity, this identity is commonly denoted by the symbol 0 (zero)
> and called an *additive identity*.
>
> _______________________________________________
> 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
>
>
>
> _______________________________________________
> Rust-dev mailing list
> [email protected]
> https://mail.mozilla.org/listinfo/rust-dev
>
>


-- 
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

Reply via email to