emacs-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: How to use a float value with either GLYPH_DEBUG or NSTRACE


From: Paul Eggert
Subject: Re: How to use a float value with either GLYPH_DEBUG or NSTRACE
Date: Mon, 21 Aug 2017 16:55:08 -0700
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.2.1

On 08/21/2017 02:30 PM, Noam Postavsky wrote:
I would imagine that "the whole
thing" is usually more than is really useful.

Yes, %.20g is not what is wanted here as it will output trailing excess digits, e.g, it outputs 0.1 as "0.10000000000000000555". What's wanted is the minimum number of digits that does not lose information. You can use dtoastr to do that, which is what number-to-string does.

E.g., something like the following (untested) C code. Although this assumes CGFloat is 'double', and outputs excess precision on 32-bit platforms where CGFloat is 'float', it would be easy to fix that if you like the idea.

#include <ftoastr.h>

void
example (CGFloat value)
{
  char buf[DBL_BUFSIZE_BOUND];
  NSTRACE ("float: %s", dtoastr (buf, sizeof buf, 0, 0, value));
}




reply via email to

[Prev in Thread] Current Thread [Next in Thread]