<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>LPC MicrocontrollersのトピックHow to copy double data into an array on MCUXpresso IDE?</title>
    <link>https://community.nxp.com/t5/LPC-Microcontrollers/How-to-copy-double-data-into-an-array-on-MCUXpresso-IDE/m-p/2043812#M57682</link>
    <description>&lt;P&gt;Hello Team,&lt;/P&gt;&lt;P&gt;The questions seems to be very basic, I know.&lt;/P&gt;&lt;P&gt;I am trying to copy a double value into a character array, I tried sprintf and snprintf, those didn't work.&lt;/P&gt;&lt;P&gt;Finally I have used gcvt that is working as expected.&lt;/P&gt;&lt;P&gt;But when I checked my environment, gcvt was commented out in stdlib.h under a specific macro.&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="sushmasan_0-1739473747463.png" style="width: 400px;"&gt;&lt;img src="https://community.nxp.com/t5/image/serverpage/image-id/323894i2CEE6C19D260F645/image-size/medium?v=v2&amp;amp;px=400" role="button" title="sushmasan_0-1739473747463.png" alt="sushmasan_0-1739473747463.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;Because of this, when I compiled the code, I am getting a warning message,&lt;/P&gt;&lt;P&gt;&lt;EM&gt;&lt;STRONG&gt;implicit declaration of function 'gcvt' [-Wimplicit-function-declaration]&lt;/STRONG&gt;&lt;/EM&gt;&lt;/P&gt;&lt;P&gt;This is the IDE version I am using currently,&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="sushmasan_1-1739474052528.png" style="width: 400px;"&gt;&lt;img src="https://community.nxp.com/t5/image/serverpage/image-id/323895iBA0E2BF19F568F82/image-size/medium?v=v2&amp;amp;px=400" role="button" title="sushmasan_1-1739474052528.png" alt="sushmasan_1-1739474052528.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;In my application, I have to compare to perform a firmware comparison, that's why trying to convert a double into a string, so that string comparison is easy. (Note: Initially I tried double comparison, but the results are unpredictable)&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;Example:&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;double a = 4.4000;&lt;/P&gt;&lt;P&gt;char arr[15] ;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;sprintf(arr,"%f",a); // arr contains full of zero's, even tried with "%lf" also.&lt;/P&gt;&lt;P&gt;snprintf(arr,4,"%f",a); // behavior is same as above&lt;/P&gt;&lt;P&gt;gcvt(a,4,arr); // arr contains the 4.45&lt;/P&gt;&lt;P&gt;Even I googled for gcvt, looks like it is deprecated and I can't use it.&lt;/P&gt;&lt;P&gt;Can someone please let me know, what is missing and why I can't use sprintf?&lt;/P&gt;&lt;P&gt;Regards,&lt;/P&gt;&lt;P&gt;San&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Thu, 13 Feb 2025 19:18:04 GMT</pubDate>
    <dc:creator>sushmasan</dc:creator>
    <dc:date>2025-02-13T19:18:04Z</dc:date>
    <item>
      <title>How to copy double data into an array on MCUXpresso IDE?</title>
      <link>https://community.nxp.com/t5/LPC-Microcontrollers/How-to-copy-double-data-into-an-array-on-MCUXpresso-IDE/m-p/2043812#M57682</link>
      <description>&lt;P&gt;Hello Team,&lt;/P&gt;&lt;P&gt;The questions seems to be very basic, I know.&lt;/P&gt;&lt;P&gt;I am trying to copy a double value into a character array, I tried sprintf and snprintf, those didn't work.&lt;/P&gt;&lt;P&gt;Finally I have used gcvt that is working as expected.&lt;/P&gt;&lt;P&gt;But when I checked my environment, gcvt was commented out in stdlib.h under a specific macro.&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="sushmasan_0-1739473747463.png" style="width: 400px;"&gt;&lt;img src="https://community.nxp.com/t5/image/serverpage/image-id/323894i2CEE6C19D260F645/image-size/medium?v=v2&amp;amp;px=400" role="button" title="sushmasan_0-1739473747463.png" alt="sushmasan_0-1739473747463.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;Because of this, when I compiled the code, I am getting a warning message,&lt;/P&gt;&lt;P&gt;&lt;EM&gt;&lt;STRONG&gt;implicit declaration of function 'gcvt' [-Wimplicit-function-declaration]&lt;/STRONG&gt;&lt;/EM&gt;&lt;/P&gt;&lt;P&gt;This is the IDE version I am using currently,&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="sushmasan_1-1739474052528.png" style="width: 400px;"&gt;&lt;img src="https://community.nxp.com/t5/image/serverpage/image-id/323895iBA0E2BF19F568F82/image-size/medium?v=v2&amp;amp;px=400" role="button" title="sushmasan_1-1739474052528.png" alt="sushmasan_1-1739474052528.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;In my application, I have to compare to perform a firmware comparison, that's why trying to convert a double into a string, so that string comparison is easy. (Note: Initially I tried double comparison, but the results are unpredictable)&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;Example:&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;double a = 4.4000;&lt;/P&gt;&lt;P&gt;char arr[15] ;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;sprintf(arr,"%f",a); // arr contains full of zero's, even tried with "%lf" also.&lt;/P&gt;&lt;P&gt;snprintf(arr,4,"%f",a); // behavior is same as above&lt;/P&gt;&lt;P&gt;gcvt(a,4,arr); // arr contains the 4.45&lt;/P&gt;&lt;P&gt;Even I googled for gcvt, looks like it is deprecated and I can't use it.&lt;/P&gt;&lt;P&gt;Can someone please let me know, what is missing and why I can't use sprintf?&lt;/P&gt;&lt;P&gt;Regards,&lt;/P&gt;&lt;P&gt;San&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 13 Feb 2025 19:18:04 GMT</pubDate>
      <guid>https://community.nxp.com/t5/LPC-Microcontrollers/How-to-copy-double-data-into-an-array-on-MCUXpresso-IDE/m-p/2043812#M57682</guid>
      <dc:creator>sushmasan</dc:creator>
      <dc:date>2025-02-13T19:18:04Z</dc:date>
    </item>
    <item>
      <title>Re: How to copy double data into an array on MCUXpresso IDE?</title>
      <link>https://community.nxp.com/t5/LPC-Microcontrollers/How-to-copy-double-data-into-an-array-on-MCUXpresso-IDE/m-p/2044302#M57692</link>
      <description>&lt;P&gt;Hi San,&lt;/P&gt;&lt;P&gt;Converting floating point numbers into strings for comparison will not help you. I recommend you have a read at &lt;A href="https://randomascii.wordpress.com/2012/02/25/comparing-floating-point-numbers-2012-edition/" target="_blank"&gt;https://randomascii.wordpress.com/2012/02/25/comparing-floating-point-numbers-2012-edition/&lt;/A&gt; and the related articles on that subject.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;About printf() and the like: what library are you using? Keep in mind that for newlib-nano you have to enable float/double support for the library, see &lt;A href="https://mcuoneclipse.com/2014/07/11/printf-and-scanf-with-gnu-arm-libraries/" target="_blank"&gt;https://mcuoneclipse.com/2014/07/11/printf-and-scanf-with-gnu-arm-libraries/&lt;/A&gt; and &lt;A href="https://community.nxp.com/t5/MCUXpresso-IDE/Printf-won-t-print-floats/m-p/1093043" target="_blank"&gt;https://community.nxp.com/t5/MCUXpresso-IDE/Printf-won-t-print-floats/m-p/1093043&lt;/A&gt; .&lt;/P&gt;&lt;P&gt;The reason is about code/data overhead involved. A comparison of different library options is here: &lt;A href="https://mcuoneclipse.com/2023/01/28/which-embedded-gcc-standard-library-newlib-newlib-nano/" target="_blank"&gt;https://mcuoneclipse.com/2023/01/28/which-embedded-gcc-standard-library-newlib-newlib-nano/&lt;/A&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I hope that helps,&lt;/P&gt;&lt;P&gt;Erich&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 14 Feb 2025 06:54:16 GMT</pubDate>
      <guid>https://community.nxp.com/t5/LPC-Microcontrollers/How-to-copy-double-data-into-an-array-on-MCUXpresso-IDE/m-p/2044302#M57692</guid>
      <dc:creator>ErichStyger</dc:creator>
      <dc:date>2025-02-14T06:54:16Z</dc:date>
    </item>
    <item>
      <title>Re: How to copy double data into an array on MCUXpresso IDE?</title>
      <link>https://community.nxp.com/t5/LPC-Microcontrollers/How-to-copy-double-data-into-an-array-on-MCUXpresso-IDE/m-p/2044675#M57693</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://community.nxp.com/t5/user/viewprofilepage/user-id/17173"&gt;@ErichStyger&lt;/a&gt;&amp;nbsp;,&lt;/P&gt;&lt;P&gt;Thanks for sharing the info.&lt;/P&gt;&lt;P&gt;There is a reason for comparing two strings.&amp;nbsp;&lt;/P&gt;&lt;P&gt;I am working on a project, where there are 2 separate devices (Example: DevA, DevB) and there is a serial communication interface used between those.&lt;/P&gt;&lt;P&gt;There is a fixed firmware version, which is let's say "3.4" (string), which is always compared with what is the firmware in DevB.&lt;/P&gt;&lt;P&gt;Before sending a data from DevA to DevB, initially there is a firmware comparison done.&lt;/P&gt;&lt;P&gt;Get the DevB firmware version (Which is a double value).&lt;/P&gt;&lt;P&gt;Since the fixed value is a string, due to this reason I am trying to convert the double to string. Hope you understand it better.&lt;/P&gt;&lt;P&gt;Also I am using sprintf not printf, in your response you mentioned printf.&lt;/P&gt;&lt;P&gt;The library I am using is -&amp;gt; Newlib (Semihost), for which "Enable Printf/scanf float" options are disabled.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 14 Feb 2025 16:10:06 GMT</pubDate>
      <guid>https://community.nxp.com/t5/LPC-Microcontrollers/How-to-copy-double-data-into-an-array-on-MCUXpresso-IDE/m-p/2044675#M57693</guid>
      <dc:creator>sushmasan</dc:creator>
      <dc:date>2025-02-14T16:10:06Z</dc:date>
    </item>
  </channel>
</rss>

