Thread (10 messages) 10 messages, 3 authors, 2016-11-23

IEEE-754 Float to int

From: Lucas Tanure <hidden>
Date: 2016-11-22 16:44:43

On Tue, Nov 22, 2016 at 4:39 PM, Greg KH [off-list ref] wrote:
On Tue, Nov 22, 2016 at 04:05:18PM +0000, Lucas Tanure wrote:
quoted
Hi,

At some point my hardware gives me a 32bit IEEE-754 float, like this :


regmap_read(device->regmap, ADDR0, &temp);

value = temp << 16;

regmap_read(device->regmap, ADDR1, &temp);

value |= temp;


So, value has a 32bit float now, and I would like to print just the
integer
quoted
part, like :
Read 26.92387 --> Print 26.
Simple, no float operations.

How I can do it ?
Just print the upper 16 bits shifted right by 16 bits.
But why would you want to print the value anyway?  Who would use it?
My hardware gives me the board temperature as a float 32bits.
And the hwmon sysfs api asks me to return the temperature as millidegree
Celsius.

To follow the hwmon sysfs api rules
<https://www.kernel.org/doc/Documentation/thermal/sysfs-api.txt>, I need to
get my float, multiply by 1000 and print the integer part.
There is a better way to do that ?

thanks,

greg k-h
Thanks

-- 
Lucas Tanure
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.kernelnewbies.org/pipermail/kernelnewbies/attachments/20161122/113d0829/attachment.html 
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help