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 part, like : Read 26.92387 --> Print 26. Simple, no float operations. How I can do it ? Thank! -- Tanure
On Tue, Nov 22, 2016 at 9:35 PM, Lucas Tanure <tanure@linux.com> wrote:
So, value has a 32bit float now, and I would like to print just the integer part, like : Read 26.92387 --> Print 26.
how about just typecasting to int ? so : int x = (int)(some-float-value) that should be it right ? -- kind regards anupam In the beginning was the lambda, and the lambda was with Emacs, and Emacs was the lambda.
On Tue, Nov 22, 2016 at 4:19 PM, Anupam Kapoor <anupam.kapoor@gmail.com> wrote:
On Tue, Nov 22, 2016 at 9:35 PM, Lucas Tanure <tanure@linux.com> wrote:
So, value has a 32bit float now, and I would like to print just the integer part, like : Read 26.92387 --> Print 26.
how about just typecasting to int ? so :
int x = (int)(some-float-value)
But this "some-float-value" must be declared as float ? Can I do that ?
that should be it right ?
-- kind regards anupam
In the beginning was the lambda, and the lambda was with Emacs, and Emacs was the lambda.
-- Lucas Tanure Embedded Developer +55 19 988176559
On Tue, Nov 22, 2016 at 9:51 PM, Lucas Tanure <tanure@linux.com> wrote:
But this "some-float-value" must be declared as float ? Can I do that ?
in your example, isn't 'value' a float type already ? -- kind regards anupam In the beginning was the lambda, and the lambda was with Emacs, and Emacs was the lambda.
No. Is a unsigned int. I'm trying to avoid floats in the kernel. On Tue, Nov 22, 2016 at 4:28 PM, Anupam Kapoor <anupam.kapoor@gmail.com> wrote:
On Tue, Nov 22, 2016 at 9:51 PM, Lucas Tanure <tanure@linux.com> wrote:
But this "some-float-value" must be declared as float ? Can I do that ?
in your example, isn't 'value' a float type already ?
-- kind regards anupam
In the beginning was the lambda, and the lambda was with Emacs, and Emacs was the lambda.
-- Lucas Tanure Embedded Developer +55 19 988176559
On Tue, Nov 22, 2016 at 04:05:18PM +0000, Lucas Tanure wrote:
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 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? thanks, greg k-h
participants (3)
-
Anupam Kapoor -
Greg KH -
Lucas Tanure