Hacker News new | ask | show | jobs
by dasb 1813 days ago
Can someone tell me what it means that "float is unsafe"? I'd never heard about that.
3 comments

It's actually float* - which is a pointer to a float (hn's formatting can eat these sometimes)

example:

    float* f = GetF();
    // In a C world, you rely on the documentation to tell you how long f is valid for. 
    SomeFunc(*f);

    // We _know_ this is safe.
    std::unique_ptr<float> f = GetF();
    SomeFunc(*f.get());
The statement was made about a float pointer. Still float precision is a problem beginners run into, too. So maybe it'll will help one reading it somewhen.

float a = 0.1f * 0.1f; assert((a - 0.01f) < 0.0001); <-- Works assert(a == 0.01f); <-- Will fail

The * has been erased by HN's markup.