xref: /aosp_15_r20/external/bazelbuild-rules_rust/test/rust_test_suite_shared/tests/helpers/mod.rs (revision d4726bddaa87cc4778e7472feed243fa4b6c267f)
1 // Binet's formula for checking Fibonacci numbers
is_fibonacci(x: i32) -> bool2 pub fn is_fibonacci(x: i32) -> bool {
3     is_perfect_square(5 * x * x + 4) || is_perfect_square(5 * x * x - 4)
4 }
5 
is_perfect_square(x: i32) -> bool6 fn is_perfect_square(x: i32) -> bool {
7     if x < 0 {
8         return false;
9     }
10     let y = (x as f64).sqrt() as i32;
11     y * y == x
12 }
13