3 ms·
> Do you also expect `sqrt(a)` to be `call sqrt` and not `sqrtss xmm0`? Of course. Who else is going to set errno when I pass negative a number?
by varajelle 5y ago
> Do you also expect `sqrt(a)` to be `call sqrt` and not `sqrtss xmm0`?
Of course. Who else is going to set errno when I pass negative a number?
- int_19h 5y agoNobody has to, if you pass it an unsigned int. Would you still expect it to be a function call then?
- matheusmoreira 5y agoSo the compiler actually can't optimize because of legacy errno cruft? That's hilarious...
- varajelle 5y agoThe compiler respects the C standard by default. According to it, puts() is the same as a printf() in some conditions, but sqrt() is not the same as the instruction. If you don't like C, you can use a dialect of it by setting some flags: -fno-math-errno if you want to optimize sqrt anyway or -fno-builtin if you don't want the compiler to replace functions calls
- matheusmoreira 5y agoI like C for the most part. I don't like the standard library. It's got stuff like errno, a thread local global variable, and that's just the simplest problem. Freestanding C turned out to be a far better language just because it has no legacy cruft weighing it down. > -fno-math-errno That's interesting, didn't know about it.
- gspr 5y agoOk, so make the question one of `call sqrt` vs `sqrtss xmm0` + a test that sets errno in case of negative then? Or even simpler: do you demand that `x = sqrt(4)` entails emitting code that calls `sqrt`?