Floating point not allowed in the kernel
Years ago, a young and relatively inexperienced lad working on a temperature sensor device driver (me) had an amusing experience (though it wasn’t quite so amusing at the time). Attempting to express a temperature value in millidegrees Celsius as a “regular” temperature value in degrees Celsius correct to three decimal places, he did something like the following:
int temperature;
double temperature_fp;
[... processing …]
temperature_fp = temperature / 1000.0;
printk(KERN_INFO "temperature is %.3f degrees C\n", temperature_fp);
It all went downhill from there!
The venerable LDD (Linux Device Drivers, by Corbet, Rubini, and Kroah-Hartman) book pointed out my error – floating-point (FP) arithmetic is not allowed in kernel space! It’s a conscious design decision; saving processor (FP) state, turning on the FP unit, working on it, then turning off and restoring the FP state is just...