I am supper tired while writing this. I think I have found an issue with dtostrf but at this point I can not relay on my brain. I think it has problems with big numbers. But that is probably for later.
At this stage I looked for dtosrtf and I found in stdlib.h, however I cannot find the implementation file.
I am going to provide the code related to dtostrf if any of you is more familiar with the terms used in the description (ex. ingroup avr_stdlib)
/**
\ingroup avr_stdlib
The dtostrf() function converts the double value passed in \c val into
an ASCII representationthat will be stored under \c s. The caller
is responsible for providing sufficient storage in \c s.
Conversion is done in the format \c "[-]d.ddd". The minimum field
width of the output string (including the possible \c '.' and the possible
sign for negative values) is given in \c width, and \c prec determines
the number of digits after the decimal sign. \c width is signed value,
negative for left adjustment.
The dtostrf() function returns the pointer to the converted string \c s.
*/
extern char *dtostrf(double __val, signed char __width,
unsigned char __prec, char *__s);
/**
\ingroup avr_stdlib
Successful termination for exit(); evaluates to 0.
*/
#define EXIT_SUCCESS 0
/**
\ingroup avr_stdlib
Unsuccessful termination for exit(); evaluates to a non-zero value.
*/
#define EXIT_FAILURE 1
is included in your code it tells the compiler: “here’s the function's prototype, don’t worry about the code that implements it, the linker will find it”
@Delta_G
This is the actual code I wrote to test. I noticed an unusual behavior in a bigger code that is why I broke it down to pieces to see what is up. I checked everything else, there are issues but I was more concerned to make sure I understand how dtostrf works. Something that I find kind of unusual (off topic) is that it does not have a way to say if it has failed. It returns a pointer to the buffer which I have not checked but cannot understand how that helps. Anyways, this a code to show why I am interested to see the implementation.
Based on this https://www.h-schmidt.net/FloatConverter/IEEE754.html
The value represented should be different unless another type of float has been use, or the dtostrf works differently on this one. I did not do a hand calculation but I did use this website as a reference to make sure there is no issue with the variable type and its limitation.
alirezasafdari:
The value represented should be different unless another type of float has been use, or the dtostrf works differently on this one. I did not do a hand calculation but I did use this website as a reference to make sure there is no issue with the variable type and its limitation.
We don't know the variable types since you didn't post complete code.
Just to help the future readers, the correct answer is given by oqibidipo. Now, I understand why they always say, we should put the '.0' at the end of the float/double value. Thank you very much oqibidipo.
The values are not the same with no doubt but the printed values were way off.