lkml.org 
[lkml]   [2001]   [Jun]   [9]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
    /
    From
    SubjectRe: temperature standard - global config option?
    Date
    Michael H. Warfiel writes:
    > On Fri, Jun 08, 2001 at 05:16:39PM -0400, Albert D. Cahalan wrote:

    >> The bits are free; the API is hard to change.
    >> Sensors might get better, at least on high-end systems.
    >> Rounding gives a constant 0.15 degree error.
    >> Only the truly stupid would assume accuracy from decimal places.
    >> Again, the bits are free; the API is hard to change.
    ...
    > No... The average person, NO, the vast majority of people,
    > DO assume accuracy from decimal places and honestly do not know the
    > difference between precision and accuracy. I've had comments on this
    > thread in private E-Mail the reinforce this impression.

    I hope you don't think people would assume that a "float" always
    has useful data in all 23 fraction bits. It is a similar case.

    So here you go, a kernel-safe conversion from C to K. It works
    from 0 to 238 degrees C. Print as hex, so user code can toss it
    into a union or maybe abuse scanf. Adjust as needed for F to K
    or for hardware with greater resolution.

    /* unsigned int degrees C --> float degrees K */
    unsigned ic_to_fk(unsigned c){
    unsigned exponent;
    unsigned tmp;

    tmp = (c<<23) + 0x88933333; /* Kelvin shifted 23 left */
    exponent = 127; /* IEEE floating-point bias */
    while(tmp&0xff000000){
    tmp >>= 1;
    exponent++;
    }
    tmp &= 0x007fffff; /* keep only the fraction */
    tmp |= exponent<<23;
    return tmp;
    }
    -
    To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
    the body of a message to majordomo@vger.kernel.org
    More majordomo info at http://vger.kernel.org/majordomo-info.html
    Please read the FAQ at http://www.tux.org/lkml/

    \
     
     \ /
      Last update: 2005-03-22 12:55    [W:3.211 / U:0.060 seconds]
    ©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site