Re: Using Math function in zephyr


Michael Hope
 

Hi Ashish.  Here's a blow-by-blow:

https://asciinema.org/a/v1LmP0FCsV2Xyv8BqNKTF8pdy

-- Michael

On Fri, 22 Dec 2017 at 11:35 ashish.shukla@... <ashish.shukla@...> wrote:
Michael, I'm a newbie in Zephyr, can you please tell the steps to be followed to turn on float support for printf.


--
Warm regards,
Ashish Shukla
Jr. Embedded Engineer
Research & Development


Please consider the environment before printing this e-mail or its attachments.

Disclaimer: The information contained herein (including any accompanying documents) is confidential and is intended solely for the addressee(s). If you have erroneously received this message, please immediately delete it and notify the sender. Also, if you are not the intended recipient, you are hereby notified that any disclosure, copying, distribution or taking any action in reliance on the contents of this message or any accompanying document is strictly prohibited and is unlawful. The organization is not responsible for any damage caused by a virus or alteration of the e-mail by a third party or otherwise. The contents of this message may not necessarily represent the views or policies of Corvi


On Fri, Dec 22, 2017 at 2:39 PM, Michael Hope <michaelh@...> wrote:

printk probably doesn't support floating point args. Give printf a try and make sure that printf float support is turned on under 'make menuconfig'.


On Fri, 22 Dec 2017, 10:04 ashish.shukla@..., <ashish.shukla@...> wrote:
Hi,

It doesn't seem to be working for me. Here's a test program

#include <zephyr.h>
#include <misc/printk.h>
#include <math.h>

void main(void)
{
printk("round up %d  \n\r",round(5.7));
printk("round down %d \n\r",round(5.2));
}

and output I get is

round up 1075314688
round down 1075052544

I'm working with nrf52840 uC.





--
Warm regards,
Ashish Shukla
Jr. Embedded Engineer
Research & Development


Please consider the environment before printing this e-mail or its attachments.

Disclaimer: The information contained herein (including any accompanying documents) is confidential and is intended solely for the addressee(s). If you have erroneously received this message, please immediately delete it and notify the sender. Also, if you are not the intended recipient, you are hereby notified that any disclosure, copying, distribution or taking any action in reliance on the contents of this message or any accompanying document is strictly prohibited and is unlawful. The organization is not responsible for any damage caused by a virus or alteration of the e-mail by a third party or otherwise. The contents of this message may not necessarily represent the views or policies of Corvi


On Fri, Dec 22, 2017 at 1:02 PM, Michael Hope <michaelh@...> wrote:
Huh, interesting.  It works for me in a test program:

#include <zephyr.h>
#include <misc/printk.h>
#include <math.h>

void main(void)
{
        printf("round up: %f\n", round(1.9));
        printf("round down: %f\n", round(3.1));
}

"""
***** BOOTING ZEPHYR OS v1.10.99- - BUILD: Dec 21 2017 21:44:19 *****
round up: 2.000000
round down: 3.000000
"""

This is on BOARD=qemu_cortex_m3 which uses the ARM soft float ABI.  There's a chance that you've got a mix of hard float / soft float code but I thought the linker checked that.

What board is this for?

-- Michael

On Fri, 22 Dec 2017 at 08:17 ashish.shukla@... <ashish.shukla@...> wrote:
Hi Michael,

After switching to new library, code compiles but it rounds off all the values to 0.


--
Warm regards,
Ashish Shukla
Jr. Embedded Engineer
Research & Development


Please consider the environment before printing this e-mail or its attachments.

Disclaimer: The information contained herein (including any accompanying documents) is confidential and is intended solely for the addressee(s). If you have erroneously received this message, please immediately delete it and notify the sender. Also, if you are not the intended recipient, you are hereby notified that any disclosure, copying, distribution or taking any action in reliance on the contents of this message or any accompanying document is strictly prohibited and is unlawful. The organization is not responsible for any damage caused by a virus or alteration of the e-mail by a third party or otherwise. The contents of this message may not necessarily represent the views or policies of Corvi


On Fri, Dec 22, 2017 at 12:01 PM, Michael Hope <michaelh@...> wrote:
Hi Ashish.  I haven't used this personally, but try switching the libc from the built-in minimal libc to newlib.  See http://docs.zephyrproject.org/subsystems/c_library.html for more.

-- Michael

On Fri, 22 Dec 2017 at 06:00 ashish.shukla@... <ashish.shukla@...> wrote:
Hello everyone !

I'm to use round()  function in zephyr. How to include math functions in zephyr ?

--
Warm regards,
Ashish Shukla
Jr. Embedded Engineer
Research & Development


Please consider the environment before printing this e-mail or its attachments.

Disclaimer: The information contained herein (including any accompanying documents) is confidential and is intended solely for the addressee(s). If you have erroneously received this message, please immediately delete it and notify the sender. Also, if you are not the intended recipient, you are hereby notified that any disclosure, copying, distribution or taking any action in reliance on the contents of this message or any accompanying document is strictly prohibited and is unlawful. The organization is not responsible for any damage caused by a virus or alteration of the e-mail by a third party or otherwise. The contents of this message may not necessarily represent the views or policies of Corvi

_______________________________________________
Zephyr-devel mailing list
Zephyr-devel@...
https://lists.zephyrproject.org/mailman/listinfo/zephyr-devel



Join devel@lists.zephyrproject.org to automatically receive all group messages.