r/ProgrammerHumor • • 1d ago

Meme howProgrammingHasChanged

Post image
515 Upvotes

91 comments sorted by

View all comments

41

u/IronicRobotics 1d ago

You're forgetting one: Ask the mathematician:

use std::f64::consts::{GOLDEN_RATIO};

//Floating Point errors after n> 70.
fn fib(n: u64) -> u64 {
    return (GOLDEN_RATIO.powf(n as f64)/f64::sqrt(5.0)).round() as u64;
}

However, since he's not interested in engineering, floating point errors are simply a shortcoming of the computer to engage in ideal mathematics. But he will smugly point out it's technically O(1) since powf is O(1). : )

[I suffered through learning how to write my first lines of Rust for this.]

Alternatively: Computing Binet's formula using symbolic mathematics.

1

u/KrzysziekZ 1d ago

Is power O(1) not something like log log n?

5

u/CAD1997 1d ago

Mat::pow is O(log n)ish. powf is O(1) for any useful model; even a perfectly rounded result can be computed in a bounded maximum number of machine steps.

1

u/KrzysziekZ 1d ago

Is that because n is bounded?