Question

I have downloaded glibc's source code, and find the function ceil() for a long time, but I cannot find it, who can tell me where is it?

And where can I find some detailed information about how to find certain function's source code in glibc's source.

Thank you.

Was it helpful?

Solution

At a guess, it's probably written in assembly language. It's basically done in three steps:

  1. Change rounding mode to "round up"
  2. round to integer (FRNDINT)
  3. restore previous rounding mode.

Unfortunately, the code to change the rounding mode is fairly ugly. The rounding mode is a few bits in the floating point control register. You can't change the FPCR inside the FPU, so you have to store it, then load it into a register on the CPU, modify some bits, store that, and load the modified version back into the FPU. Then you execute one FP instruction, and do the same again, but in reverse.

I do seem to recall some of Intel's literature years ago talking about this, and (perhaps) talking about a better way to handle it -- but I could be imagining that, and even if I'm not, I don't remember how their improved version worked.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top