Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What does the _f32 suffix mean?

Tags:

rust

I came across this line of code written in rust and do not understand what is happening here. Can anyone explain this line of code written in rust?

let decimal = 65.4321_f32;

What does _f32 do?

Thanks in advance :)


2 Answers

In rust you can specify numeric types but adding a trailing tag:

0usize
0i32
0u32
0f32
0f64
...

Also you have the possibility of adding _ as a visual separator in numbers, it doesn't affect the final value itself (1_2_3 would be 123 anyway):

10
100
1000
10_000
100_000
1_000_000
...

By mixing both of them you arrive at the final form used in your question where the _ is used to separate the type tag itself:

10_000.1001_f32

You can take a look at the literal expressions documentation

like image 118
Netwave Avatar answered Jan 23 '26 14:01

Netwave


It declares the type as a 32-bit float. There is a brief discussion here. The "_" is just semantic sugar, separating the value from the type.

like image 36
BoCoKeith Avatar answered Jan 23 '26 16:01

BoCoKeith



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!