Hacker News new | past | comments | ask | show | jobs | submit login

> Is f32 the only suffix for float literals?

Nope. `f32` is for single-precision floats, and `f64` is for double-precision floats. There have been some people lobbying for `f16` and `f128` as well.

Also, you don't need to use those suffixes. I imagine the OP is using them for maximum explicitness, but you can just write `1.0` and it will be inferred to a floating-point type as necessary (contrast `1`, which will be inferred to an integral type).




GLSL programmers may rejoice in learning that `1.` is accepted syntax too.


Having used Rust since pre-release I'm slightly embarrassed that I'm only learning about this today.


That's ok. I presume you weren't a C/C++ dev before, that's old school shorthand for C coders that don't want to type out suffixes or cast numeric values.


> I imagine the OP is using them for maximum explicitness

I used them because that's the style that was used inside of std::f32;

  const INFINITY: f32 = 1.0 / 0.0;
totally works.




Consider applying for YC's Spring batch! Applications are open till Feb 11.

Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: