* [rust-dev] About const
@ 2015-01-04 9:37 Pim Schellart
2015-01-04 16:21 ` Manish Goregaokar
0 siblings, 1 reply; 4+ messages in thread
From: Pim Schellart @ 2015-01-04 9:37 UTC (permalink / raw)
To: rust-dev
Dear Rust Developers,
here is another ignorant question so feel free to ignore.
When reading the guide I came across "std::f64::consts::PI” for pi. Now I was wondering why there are separate constants defined for 32 and 64 bit floats and how this will work with generics. Do you always have to define two functions to work on f32 and f64 or is std::f64::consts::PI cast down to f32 in an equation with 32 bit variables? Is there also a general `typeless’ PI (or other fundamental constants), as in Go for example?
Kind Regards,
Pim
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [rust-dev] About const
2015-01-04 9:37 [rust-dev] About const Pim Schellart
@ 2015-01-04 16:21 ` Manish Goregaokar
2015-01-04 16:57 ` Philippe Daouadi
0 siblings, 1 reply; 4+ messages in thread
From: Manish Goregaokar @ 2015-01-04 16:21 UTC (permalink / raw)
To: Pim Schellart; +Cc: rust-dev
[-- Attachment #1: Type: text/plain, Size: 1148 bytes --]
We have two types of floats, there is a Pi of both precision levels. I
don't think it's anything more than that. You should be able to cast
between the two, but that's it I guess. Rust tries to give explicit control
over such things.
There is a Float trait (might have been renamed) if you want to use
generics.
-Manish Goregaokar
On Sun, Jan 4, 2015 at 3:07 PM, Pim Schellart <p.schellart@gmail.com> wrote:
> Dear Rust Developers,
>
> here is another ignorant question so feel free to ignore.
> When reading the guide I came across "std::f64::consts::PI” for pi. Now I
> was wondering why there are separate constants defined for 32 and 64 bit
> floats and how this will work with generics. Do you always have to define
> two functions to work on f32 and f64 or is std::f64::consts::PI cast down
> to f32 in an equation with 32 bit variables? Is there also a general
> `typeless’ PI (or other fundamental constants), as in Go for example?
>
> Kind Regards,
>
> Pim
> _______________________________________________
> Rust-dev mailing list
> Rust-dev@mozilla.org
> https://mail.mozilla.org/listinfo/rust-dev
>
[-- Attachment #2: Type: text/html, Size: 1688 bytes --]
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [rust-dev] About const
2015-01-04 16:21 ` Manish Goregaokar
@ 2015-01-04 16:57 ` Philippe Daouadi
2015-01-04 17:08 ` Pim Schellart
0 siblings, 1 reply; 4+ messages in thread
From: Philippe Daouadi @ 2015-01-04 16:57 UTC (permalink / raw)
To: Manish Goregaokar, Pim Schellart; +Cc: rust-dev
[-- Attachment #1: Type: text/plain, Size: 1612 bytes --]
If you want a generic pi, you should use the one in the Float trait
If you have
let x : f64 = ...;
x * Float::pi() will resolve to f64 pi
Philippe
On 01/04/2015 05:21 PM, Manish Goregaokar wrote:
> We have two types of floats, there is a Pi of both precision levels. I
> don't think it's anything more than that. You should be able to cast
> between the two, but that's it I guess. Rust tries to give explicit
> control over such things.
>
> There is a Float trait (might have been renamed) if you want to use
> generics.
>
> -Manish Goregaokar
>
> On Sun, Jan 4, 2015 at 3:07 PM, Pim Schellart <p.schellart@gmail.com
> <mailto:p.schellart@gmail.com>> wrote:
>
> Dear Rust Developers,
>
> here is another ignorant question so feel free to ignore.
> When reading the guide I came across "std::f64::consts::PI” for
> pi. Now I was wondering why there are separate constants defined
> for 32 and 64 bit floats and how this will work with generics. Do
> you always have to define two functions to work on f32 and f64 or
> is std::f64::consts::PI cast down to f32 in an equation with 32
> bit variables? Is there also a general `typeless’ PI (or other
> fundamental constants), as in Go for example?
>
> Kind Regards,
>
> Pim
> _______________________________________________
> Rust-dev mailing list
> Rust-dev@mozilla.org <mailto:Rust-dev@mozilla.org>
> https://mail.mozilla.org/listinfo/rust-dev
>
>
>
>
> _______________________________________________
> Rust-dev mailing list
> Rust-dev@mozilla.org
> https://mail.mozilla.org/listinfo/rust-dev
[-- Attachment #2: Type: text/html, Size: 3292 bytes --]
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [rust-dev] About const
2015-01-04 16:57 ` Philippe Daouadi
@ 2015-01-04 17:08 ` Pim Schellart
0 siblings, 0 replies; 4+ messages in thread
From: Pim Schellart @ 2015-01-04 17:08 UTC (permalink / raw)
To: Philippe Daouadi; +Cc: rust-dev
Ok, thanks!
> On 04 Jan 2015, at 17:57, Philippe Daouadi <blastrock0@free.fr> wrote:
>
> If you want a generic pi, you should use the one in the Float trait
>
> If you have
> let x : f64 = ...;
> x * Float::pi() will resolve to f64 pi
>
> Philippe
>
> On 01/04/2015 05:21 PM, Manish Goregaokar wrote:
>> We have two types of floats, there is a Pi of both precision levels. I don't think it's anything more than that. You should be able to cast between the two, but that's it I guess. Rust tries to give explicit control over such things.
>>
>> There is a Float trait (might have been renamed) if you want to use generics.
>>
>> -Manish Goregaokar
>>
>> On Sun, Jan 4, 2015 at 3:07 PM, Pim Schellart <p.schellart@gmail.com> wrote:
>> Dear Rust Developers,
>>
>> here is another ignorant question so feel free to ignore.
>> When reading the guide I came across "std::f64::consts::PI” for pi. Now I was wondering why there are separate constants defined for 32 and 64 bit floats and how this will work with generics. Do you always have to define two functions to work on f32 and f64 or is std::f64::consts::PI cast down to f32 in an equation with 32 bit variables? Is there also a general `typeless’ PI (or other fundamental constants), as in Go for example?
>>
>> Kind Regards,
>>
>> Pim
>> _______________________________________________
>> Rust-dev mailing list
>> Rust-dev@mozilla.org
>> https://mail.mozilla.org/listinfo/rust-dev
>>
>>
>>
>> _______________________________________________
>> Rust-dev mailing list
>>
>> Rust-dev@mozilla.org
>> https://mail.mozilla.org/listinfo/rust-dev
>
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2015-01-04 17:08 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-01-04 9:37 [rust-dev] About const Pim Schellart
2015-01-04 16:21 ` Manish Goregaokar
2015-01-04 16:57 ` Philippe Daouadi
2015-01-04 17:08 ` Pim Schellart
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox