From: Anders Lindgren <andlind@gmail.com>
To: Keith David Bershatsky <esq@lawlist.com>
Cc: Alan Third <alan@idiocy.org>, Paul Eggert <eggert@cs.ucla.edu>,
emacs-devel <emacs-devel@gnu.org>,
Noam Postavsky <npostavs@users.sourceforge.net>
Subject: Re: How to use a float value with either GLYPH_DEBUG or NSTRACE
Date: Tue, 22 Aug 2017 10:23:36 +0200 [thread overview]
Message-ID: <CABr8ebYuXVqQvHgRkzUHaTcgRHq-Xzn55Nk=nugRkUsySO=X0g@mail.gmail.com> (raw)
In-Reply-To: <m2pobo442q.wl%esq@lawlist.com>
[-- Attachment #1: Type: text/plain, Size: 2009 bytes --]
Hi!
I think(*) you can use "%a" to print the hexadecimal representation of a
floating point number. This prints the floating point number exactly, down
to the last bit in the mantissa. It looks like 0x0.3p10, where 0x0.3 is the
"significant" part and "p10" the binary exponent, and it represents the
number 0x0.3 * 2^10.
In the tradition of NSTRACE, you can define a macro for the format string
(to ensure that all functions that print colors use the same format). For
example:
#define NSTRACE_FMT_RGB "(R:%a G:%a B:%a)"
And another to push the arguments:
#define NSTRACE_ARG_RGB(color) (color).redComponent,
(color).greenComponent, (color).blueComponent
With this, you should be able to print the color values ergonomically using:
NSTRACE("The colors are " NSTRACE_FMT_RGB,
NSTRACE_ARG_RGB([background_color colorUsingDefaultColorSpace]));
To make this even shorter, you can define the macro "NSTRACE_RGB" along the
lines of "NSTRACE_SIZE" and "NSTRACE_POINT".
* Currently, I can't test this, as I have no mac nearby.
-- Anders
On Tue, Aug 22, 2017 at 6:30 AM, Keith David Bershatsky <esq@lawlist.com>
wrote:
> Thank you, Paul, for the suggestion to use dtoastr. I tried that and a
> few variations, but got stuck because dtoastr returns an `int` and `%s`
> expects a `char` value. Substituting `%s` for `%d` did not yield the
> correct results.
>
> Keith
>
> ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
>
> DATE: [08-21-2017 16:55:08] <21 Aug 2017 16:55:08 -0700>
> FROM: Paul Eggert <eggert@cs.ucla.edu>
> >
> > * * *
> >
> > 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));
> > }
>
>
[-- Attachment #2: Type: text/html, Size: 2753 bytes --]
next prev parent reply other threads:[~2017-08-22 8:23 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-08-22 4:30 How to use a float value with either GLYPH_DEBUG or NSTRACE Keith David Bershatsky
2017-08-22 8:23 ` Anders Lindgren [this message]
2017-08-22 11:32 ` Noam Postavsky
2017-08-22 11:51 ` Anders Lindgren
2017-08-22 15:47 ` Paul Eggert
-- strict thread matches above, loose matches on Subject: below --
2017-08-22 17:04 Keith David Bershatsky
2017-08-21 21:45 Keith David Bershatsky
2017-08-21 20:51 Keith David Bershatsky
2017-08-21 21:30 ` Noam Postavsky
2017-08-21 23:55 ` Paul Eggert
2017-08-21 17:07 Keith David Bershatsky
2017-08-21 20:07 ` Alan Third
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to='CABr8ebYuXVqQvHgRkzUHaTcgRHq-Xzn55Nk=nugRkUsySO=X0g@mail.gmail.com' \
--to=andlind@gmail.com \
--cc=alan@idiocy.org \
--cc=eggert@cs.ucla.edu \
--cc=emacs-devel@gnu.org \
--cc=esq@lawlist.com \
--cc=npostavs@users.sourceforge.net \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this external index
https://git.savannah.gnu.org/cgit/emacs.git
https://git.savannah.gnu.org/cgit/emacs/org-mode.git
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.