Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.c > #66223

Re: Floating point to string, and back via `%a'...

From Keith Thompson <kst-u@mib.org>
Newsgroups comp.lang.c
Subject Re: Floating point to string, and back via `%a'...
Date 2015-07-22 16:58 -0700
Organization None to speak of
Message-ID <lnzj2nzqwh.fsf@kst-u.example.com> (permalink)
References (1 earlier) <87mvyn51bm.fsf@bsb.me.uk> <mop2i6$bkq$1@speranza.aioe.org> <lnfv4f26t4.fsf@kst-u.example.com> <mop6qm$juc$1@speranza.aioe.org> <1a90raht141tr0c3kvkafnvrvqqf8s1qov@4ax.com>

Show all headers | View raw


Robert Wessel <robertwessel2@yahoo.com> writes:
> On Wed, 22 Jul 2015 15:51:54 -0700, "Chris M. Thomasson"
> <nospam@nospam.nospam> wrote:
>
>>> "Keith Thompson"  wrote in message 
>>> news:lnfv4f26t4.fsf@kst-u.example.com...
>>
>>[...]
>>> What output do you get using MSVC?  If it's significantly different,
>>> there may well be a bug in MSVC (presumably in its runtime library).
>>
>>I get with with MING 4.8 on windows:
>>_________________________________________
>>in  = 1.0123456789 = 0x1.032916p+0
>>buf = "0x1.032916p+0"
>>sscanf returned 0
>>out = 0.0000000000 = 0x0.000000p+0
>>in != out
>>_________________________________________
>>
>>So, the nasty problem has to be in ms runtime shi%.
>>
>>Damn!  ;^( 
>
>
> From the MSDN VS 2015 scanf types page:
>
> "The a and A specifiers (see printf Type Field Characters) are not
> available with scanf."
>
> https://msdn.microsoft.com/en-us/library/6ttkkkhh.aspx

Well there it is -- and that's why sscanf is returning 0.

The purpose of "%a" is to have a realtively simple way to convert a
floating-point number to a string without loss of precision.

Using "%g" with a large precision, such as "%.64g", will likely achieve
the same result, but not as reliably.  Or you can borrow code from an
open source implementation of scanf.

-- 
Keith Thompson (The_Other_Keith) kst-u@mib.org  <http://www.ghoti.net/~kst>
Working, but not speaking, for JetHead Development, Inc.
"We must do something.  This is something.  Therefore, we must do this."
    -- Antony Jay and Jonathan Lynn, "Yes Minister"

Back to comp.lang.c | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread


Thread

Floating point to string, and back via `%a'... "Chris M. Thomasson" <nospam@nospam.nospam> - 2015-07-22 12:46 -0700
  Re: Floating point to string, and back via `%a'... James Kuyper <jameskuyper@verizon.net> - 2015-07-22 16:19 -0400
    Re: Floating point to string, and back via `%a'... "Chris M. Thomasson" <nospam@nospam.nospam> - 2015-07-22 13:49 -0700
      Re: Floating point to string, and back via `%a'... Keith Thompson <kst-u@mib.org> - 2015-07-22 14:01 -0700
      Re: Floating point to string, and back via `%a'... James Kuyper <jameskuyper@verizon.net> - 2015-07-22 17:18 -0400
        Re: Floating point to string, and back via `%a'... "Chris M. Thomasson" <nospam@nospam.nospam> - 2015-07-22 14:22 -0700
  Re: Floating point to string, and back via `%a'... Keith Thompson <kst-u@mib.org> - 2015-07-22 13:40 -0700
    Re: Floating point to string, and back via `%a'... "Chris M. Thomasson" <nospam@nospam.nospam> - 2015-07-22 14:01 -0700
      Re: Floating point to string, and back via `%a'... Keith Thompson <kst-u@mib.org> - 2015-07-22 14:12 -0700
        Re: Floating point to string, and back via `%a'... "Chris M. Thomasson" <nospam@nospam.nospam> - 2015-07-22 14:20 -0700
          Re: Floating point to string, and back via `%a'... "Chris M. Thomasson" <nospam@nospam.nospam> - 2015-07-22 14:24 -0700
          Re: Floating point to string, and back via `%a'... glen herrmannsfeldt <gah@ugcs.caltech.edu> - 2015-07-22 21:30 +0000
            Re: Floating point to string, and back via `%a'... "Chris M. Thomasson" <nospam@nospam.nospam> - 2015-07-22 14:39 -0700
          Re: Floating point to string, and back via `%a'... Joe Pfeiffer <pfeiffer@cs.nmsu.edu> - 2015-07-22 19:49 -0600
  Re: Floating point to string, and back via `%a'... Ben Bacarisse <ben.usenet@bsb.me.uk> - 2015-07-22 22:28 +0100
    Re: Floating point to string, and back via `%a'... "Chris M. Thomasson" <nospam@nospam.nospam> - 2015-07-22 14:34 -0700
      Re: Floating point to string, and back via `%a'... Keith Thompson <kst-u@mib.org> - 2015-07-22 14:58 -0700
        Re: Floating point to string, and back via `%a'... "Chris M. Thomasson" <nospam@nospam.nospam> - 2015-07-22 15:43 -0700
        Re: Floating point to string, and back via `%a'... "Chris M. Thomasson" <nospam@nospam.nospam> - 2015-07-22 15:45 -0700
        Re: Floating point to string, and back via `%a'... "Chris M. Thomasson" <nospam@nospam.nospam> - 2015-07-22 15:51 -0700
          Re: Floating point to string, and back via `%a'... Robert Wessel <robertwessel2@yahoo.com> - 2015-07-22 18:21 -0500
            Re: Floating point to string, and back via `%a'... Keith Thompson <kst-u@mib.org> - 2015-07-22 16:58 -0700
        Re: Floating point to string, and back via `%a'... Keith Thompson <kst-u@mib.org> - 2015-07-22 16:52 -0700
        Re: Floating point to string, and back via `%a'... Keith Thompson <kst-u@mib.org> - 2015-07-22 17:08 -0700
      Re: Floating point to string, and back via `%a'... Ben Bacarisse <ben.usenet@bsb.me.uk> - 2015-07-23 00:01 +0100
        Re: Floating point to string, and back via `%a'... "Chris M. Thomasson" <nospam@nospam.nospam> - 2015-07-22 19:40 -0700
          Re: Floating point to string, and back via `%a'... Keith Thompson <kst-u@mib.org> - 2015-07-22 22:32 -0700
          Re: Floating point to string, and back via `%a'... Ben Bacarisse <ben.usenet@bsb.me.uk> - 2015-07-23 11:07 +0100
            Re: Floating point to string, and back via `%a'... Ben Bacarisse <ben.usenet@bsb.me.uk> - 2015-07-23 11:25 +0100
              Re: Floating point to string, and back via `%a'... "Chris M. Thomasson" <nospam@nospam.nospam> - 2015-07-24 11:44 -0700
            Re: Floating point to string, and back via `%a'... "Chris M. Thomasson" <nospam@nospam.nospam> - 2015-07-24 11:47 -0700

csiph-web