0
0
Rustprogramming~10 mins

Floating point types in Rust - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to declare a 32-bit floating point variable.

Rust
let pi: [1] = 3.14f32;
Drag options to blanks, or click blank then click option'
Achar
Bi32
Cbool
Df32
Attempts:
3 left
๐Ÿ’ก Hint
Common Mistakes
Using integer types like i32 for floating point numbers.
Using boolean or character types for numbers.
2fill in blank
medium

Complete the code to declare a 64-bit floating point variable.

Rust
let e: [1] = 2.71828;
Drag options to blanks, or click blank then click option'
Ausize
Bi64
Cf64
Dbool
Attempts:
3 left
๐Ÿ’ก Hint
Common Mistakes
Using integer types like i64 instead of floating point.
Confusing usize with floating point types.
3fill in blank
hard

Fix the error in the code by choosing the correct floating point type.

Rust
let gravity: [1] = 9.81;
Drag options to blanks, or click blank then click option'
Af64
Bf128
Cint
Dstr
Attempts:
3 left
๐Ÿ’ก Hint
Common Mistakes
Using non-existent types like f128 or int.
Using string types for numbers.
4fill in blank
hard

Fill both blanks to create a vector of 32-bit floating point numbers.

Rust
let numbers: Vec<[1]> = vec![1.0f32, 2.0f32, 3.0f32];
let first: [2] = numbers[0];
Drag options to blanks, or click blank then click option'
Af32
Bi32
Cf64
Dbool
Attempts:
3 left
๐Ÿ’ก Hint
Common Mistakes
Mixing integer and floating point types.
Using f64 when the vector is f32.
5fill in blank
hard

Fill all three blanks to create a function that returns a 64-bit floating point number.

Rust
fn calculate_area(radius: [1]) -> [2] {
    let pi: [3] = 3.14159;
    pi * radius * radius
}
Drag options to blanks, or click blank then click option'
Af32
Bf64
Di32
Attempts:
3 left
๐Ÿ’ก Hint
Common Mistakes
Mixing f32 and f64 types.
Using integer types for floating point calculations.