8 ms·
Can someone tell me what it means that "float is unsafe"? I'd never heard about that.
by dasb 5y ago
Can someone tell me what it means that "float is unsafe"? I'd never heard about that.
- nly 5y agoThe * has been erased by HN's markup.
- maccard 5y agoIt'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());
- deleted 5y ago[deleted]
- bionade24 5y agoThe 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