# Should pi be available as \`f32::PI\`, etc?

**URL:** <https://internals.rust-lang.org/t/should-pi-be-available-as-f32-pi-etc/18670>\
**Category:** libs\
**Created:** [April 13, 2023, 1:30pm UTC](https://internals.rust-lang.org/t/should-pi-be-available-as-f32-pi-etc/18670 "2023-04-13T13:30:32Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![pommicket](https://sea2.discourse-cdn.com/flex002/user_avatar/internals.rust-lang.org/pommicket/32/10756_2.png) [@pommicket](https://internals.rust-lang.org/u/pommicket)\
**Post date:** [April 13, 2023, 1:30pm UTC](https://internals.rust-lang.org/t/should-pi-be-available-as-f32-pi-etc/18670/1 "2023-04-13T13:30:32Z")

</div>

Should the constants in `std::f32::consts` (and `std::f64::consts`) be made also available as associated constants (cf `f32::NAN`)?

`f32::PI` is much nicer to type & read than `std::f32::consts::PI`. I don't see why mathematical constants need to be relegated to such a long path ):

(There's always the possibility of doing `use std::f32::consts as f32c;` in every file but that's kind of annoying...)

I know you wouldn't be able to do `use f32::PI;` so perhaps `std::f32::consts` shouldn't be deprecated/removed like `std::u32` is planned to be, & I don't know how people feel about having the same constants defined in multiple places (maybe that's one reason for not doing this).

Also: for what it's worth the popular crates `half` and `fixed` already do this for their types.

---

<div class="post-metadata">

**Author:** ![josh](https://sea2.discourse-cdn.com/flex002/user_avatar/internals.rust-lang.org/josh/32/5934_2.png) [@josh](https://internals.rust-lang.org/u/josh)\
**Post date:** [April 13, 2023, 2:44pm UTC](https://internals.rust-lang.org/t/should-pi-be-available-as-f32-pi-etc/18670/2 "2023-04-13T14:44:50Z")

</div>

> [@pommicket](#):
>
> I know you wouldn't be able to do `use f32::PI`

I would love to see that fixed.

---

<div class="post-metadata">

**Author:** ![faern](https://sea2.discourse-cdn.com/flex002/user_avatar/internals.rust-lang.org/faern/32/3580_2.png) [@faern](https://internals.rust-lang.org/u/faern)\
**Post date:** [April 18, 2023, 2:02pm UTC](https://internals.rust-lang.org/t/should-pi-be-available-as-f32-pi-etc/18670/3 "2023-04-18T14:02:03Z")

</div>

I would love to see all the mathematical constants available directly on the float types! This has been brought up in the past, but was shot down in the RFC that moved some float constants from the modules to the type: [https://github.com/rust-lang/rfcs/pull/2700](https://github.com/rust-lang/rfcs/pull/2700)

But maybe people have changed their minds since then?

---

<div class="post-metadata">

**Author:** ![kornel](https://sea2.discourse-cdn.com/flex002/user_avatar/internals.rust-lang.org/kornel/32/2711_2.png) [@kornel](https://internals.rust-lang.org/u/kornel)\
**Post date:** [April 19, 2023, 1:53am UTC](https://internals.rust-lang.org/t/should-pi-be-available-as-f32-pi-etc/18670/4 "2023-04-19T01:53:38Z")

</div>

The reason seems to be that Rust doesn't support `use`ing associated constants, so:

```rust
use std::f32::consts::PI; // works
use f32::PI; // not supported

short(PI);

```

---

<div class="post-metadata">

**Author:** ![pommicket](https://sea2.discourse-cdn.com/flex002/user_avatar/internals.rust-lang.org/pommicket/32/10756_2.png) [@pommicket](https://internals.rust-lang.org/u/pommicket)\
**Post date:** [April 19, 2023, 4:56pm UTC](https://internals.rust-lang.org/t/should-pi-be-available-as-f32-pi-etc/18670/5 "2023-04-19T16:56:01Z")

</div>

By the way I made an RFC for this: [RFC for associated mathematical constants by pommicket · Pull Request #3418 · rust-lang/rfcs · GitHub](https://github.com/rust-lang/rfcs/pull/3418)

---

<div class="post-metadata">

**Author:** ![system](https://sea2.discourse-cdn.com/flex002/user_avatar/internals.rust-lang.org/system/32/14092_2.png) [@system](https://internals.rust-lang.org/u/system)\
**Post date:** [July 18, 2023, 4:57pm UTC](https://internals.rust-lang.org/t/should-pi-be-available-as-f32-pi-etc/18670/6 "2023-07-18T16:57:00Z")

</div>

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.
