All of lore.kernel.org
 help / color / mirror / Atom feed
* Question concerning sensors chips.c alarm handling
@ 2005-05-19  6:25 James Olin Oden
  2005-05-19  6:25 ` Jean Delvare
  2005-05-19  6:25 ` Mark Studebaker
  0 siblings, 2 replies; 3+ messages in thread
From: James Olin Oden @ 2005-05-19  6:25 UTC (permalink / raw)
  To: lm-sensors

Hi All,

I was looking in the sensors program's chips.c file at the various
print_*() routines and found the following code:

	if (!sensors_get_feature(*name,SENSORS_ADM1025_ALARMS,&cur))	
	    alarms = cur + 0.5;
  	else {
	    printf("ERROR: Can't get alarm data!\n");
	    alarms = 0;
	}

repeated in various routines for various chips.  Why is 0.5 added to 
the alarm mask value?

Thanks...james

P.S.  Looking at implenting a print routine for the lm93, and was 
basically looking at copying code from LM87 print routine and going
from there.

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Question concerning sensors chips.c alarm handling
  2005-05-19  6:25 Question concerning sensors chips.c alarm handling James Olin Oden
  2005-05-19  6:25 ` Jean Delvare
@ 2005-05-19  6:25 ` Mark Studebaker
  1 sibling, 0 replies; 3+ messages in thread
From: Mark Studebaker @ 2005-05-19  6:25 UTC (permalink / raw)
  To: lm-sensors

rounding since sensors_get_feature() returns a float.
it ensures that you get back to the same integer bitmask you had to begin with.
mds

James Olin Oden wrote:
> Hi All,
> 
> I was looking in the sensors program's chips.c file at the various
> print_*() routines and found the following code:
> 
> 	if (!sensors_get_feature(*name,SENSORS_ADM1025_ALARMS,&cur))	
> 	    alarms = cur + 0.5;
>   	else {
> 	    printf("ERROR: Can't get alarm data!\n");
> 	    alarms = 0;
> 	}
> 
> repeated in various routines for various chips.  Why is 0.5 added to 
> the alarm mask value?
> 
> Thanks...james
> 
> P.S.  Looking at implenting a print routine for the lm93, and was 
> basically looking at copying code from LM87 print routine and going
> from there.
> 
> 

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Question concerning sensors chips.c alarm handling
  2005-05-19  6:25 Question concerning sensors chips.c alarm handling James Olin Oden
@ 2005-05-19  6:25 ` Jean Delvare
  2005-05-19  6:25 ` Mark Studebaker
  1 sibling, 0 replies; 3+ messages in thread
From: Jean Delvare @ 2005-05-19  6:25 UTC (permalink / raw)
  To: lm-sensors

> I was looking in the sensors program's chips.c file at the various
> print_*() routines and found the following code:
> 
> 	if (!sensors_get_feature(*name,SENSORS_ADM1025_ALARMS,&cur))
> 	    alarms = cur + 0.5;
>   	else {
> 	    printf("ERROR: Can't get alarm data!\n");
> 	    alarms = 0;
> 	}
> 
> repeated in various routines for various chips.  Why is 0.5 added to
> the alarm mask value?

Values are retrieved from libsensors as floating point numbers, not integers.
When converting from floating point to interger, C will simply drop the
non-interger part. Thus, 12345677.99999 will be converted to 12345677 while we
are obviously expecting 12345678. Thus it is usually considered a good
practice to add 0.5 to any floating point value before converting it to an
integer.

Note that I am not sure it is needed in our specific case. The "double" type
should be able to handle 32-bit integer values without losses, and the drivers
don't export alarm values over 32-bit as far as I know. So I guess that the "+
0.5" operation is theoretical and we don't actually need it. Feel free to drop
it in your own code unless you notice it is actually needed.

-- 
Jean Delvare
http://khali.linux-fr.org/

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2005-05-19  6:25 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2005-05-19  6:25 Question concerning sensors chips.c alarm handling James Olin Oden
2005-05-19  6:25 ` Jean Delvare
2005-05-19  6:25 ` Mark Studebaker

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.