From the course: First Look: Rust
Unlock the full course today
Join today to access over 22,600 courses taught by industry experts or purchase this course individually.
Scalar data types: Floats - Rust Tutorial
From the course: First Look: Rust
Scalar data types: Floats
- Rust also has two primitive types for floating point numbers, which are numbers with decimal points. Rust floating point types are f32 and f64 which are 32 bits and 64 bits in size, respectively. If you see the variable here, x has the value 2.0, which by default, the Rust allocates 64 bits of space and it's a floating point. If you need to explicitly annotate the type to be 32 bits, we can do as in the variable y. Add a colon, followed by f32, and then assign it to whatever value you need. As in most other programming languages, a boolean type in Rust has two possible values: true and false. The boolean type in Rust is specified using the keyword bool. Typically, these types are used whenever flags need to be set, and based on the value of the flag, allow the program to perform a certain operation. So, if we want to set the value of t to be true, we just write true, which is a keyword here. And true in other programming languages you would know this as one. And if we want to…
Practice while you learn with exercise files
Download the files the instructor uses to teach the course. Follow along and learn by watching, listening and practicing.
Contents
-
-
-
-
Variables and mutability3m 15s
-
(Locked)
Scalar data types: Integers4m 2s
-
(Locked)
Scalar data types: Floats2m 10s
-
(Locked)
Compound data types: Tuples3m 50s
-
(Locked)
Compound data types: Arrays3m 55s
-
(Locked)
How functions work4m 12s
-
(Locked)
Return a value from a function3m 44s
-
(Locked)
Control flow: if/else6m 9s
-
(Locked)
Control flow: While loops3m 19s
-
(Locked)
Control flow: For loops2m 9s
-
-
-
-
-
-