Pelles C > Announcements

Version 9.00 (RC2) is now available

<< < (2/3) > >>

rchockxm:
Nice Jobs

Thanks Pelle.

Pelle:
MrBcx, rchockxm: Thank you!

jj2007:

--- Quote from: Pelle on June 19, 2018, 06:31:28 PM ---Enhanced precision for last digit when converting from string to floating-point. This affects at least strtof(), strtod(), strtold(), atof(), wcstof(), wcstod(), wcstold(), and %e, %g, %f, %a conversion specifiers for scanf family of functions.
--- End quote ---

Congrats, I just installed RC3, and it works fine. I was curious, so I did a quick test with this strtold() example:

--- Code: ---/* strtold example */
#include <stdio.h>      /* printf, NULL */
#include <stdlib.h>     /* strtold */

int main ()
{
  char szOrbits[] = "90613.305 365.24";
  char * pEnd;
  long double f1, f2;
  f1 = strtod (szOrbits, &pEnd);
  f2 = strtod (pEnd, NULL);
  printf ("Pluto takes %.20d years to complete an orbit.\n", f1/f2);
  return 0;
}
--- End code ---

Results:
--- Code: ----3127531395801304400 Gcc (rubbish...)
248.0925008213777100 Visual C (strtod - there is no strtold)
248.0925008213777095 Pelles C
248.0925008213776989 MasmBasic REAL8 f1/f2
248.0925008213777242 MasmBasic using fdiv
248.0925008213777242 Windows Calc
--- End code ---

Same for

--- Code: ---printf ("Pluto takes %.20llf years to complete an orbit.\n", strtold (szOrbits, &pEnd)/strtold (pEnd, NULL));
--- End code ---
It seems that f1 and f2 are doubles, i.e. REAL8, and not long doubles, i.e. REAL10. Is that correct?

TimoVJL:

--- Quote from: jj2007 on July 09, 2018, 03:16:59 AM ---Results:-3127531395801304400   Gcc (rubbish...)
--- End quote ---
gcc/mingw needs __USE_MINGW_ANSI_STDIO for printf and %Lf for long doubles

--- Code: ---Pluto takes 248.092500821377724238 years to complete an orbit.
--- End code ---


--- Quote from: jj2007 on July 09, 2018, 03:16:59 AM ---It seems that f1 and f2 are doubles, i.e. REAL8, and not long doubles, i.e. REAL10. Is that correct?
--- End quote ---
Sadly, with msvc and compatible, yes, long double is just an alias for double.
Visual C++ started using it ?

With gcc and icc, no, they have long double.

With mingw gcc use:

--- Code: ---#define __USE_MINGW_ANSI_STDIO 1
#define __USE_MINGW_STRTOX 1
...
printf ("Pluto takes %.20Lf years to complete an orbit.\n", strtold (szOrbits, &pEnd)/strtold (pEnd, NULL));

--- End code ---

EDIT:
Why function printf does not support long double?

So Microsoft Quick C dropped original long double.

jj2007:
Thanks, Timo. I actually meant Pelles C when I asked if "short" doubles are being used.

With #define __USE_MINGW_ANSI_STDIO 1, the order is now:

--- Code: ---248.0925008213777100 Visual C (strtod - there is no strtold)
248.0925008213777095 Pelles C
248.0925008213777242 MasmBasic (fdiv)
248.0925008213777242 MasmBasic (REAL10 variables)
248.0925008213777242 Windows Calc
248.092500821377724237 Gcc (#define __USE_MINGW_ANSI_STDIO 1)
248.092500821377724236 Windows Calc
--- End code ---

So how can GCC achieve two more digits of precision...? The answer is under the hood (surprise, surprise):

--- Code: ---  asm("int $3");
  f3=f1/f2;
  asm("nop");
--- End code ---

Navigation

[0] Message Index

[#] Next page

[*] Previous page

Go to full version