From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!.POSTED!not-for-mail From: Anders Lindgren Newsgroups: gmane.emacs.devel Subject: Re: How to use a float value with either GLYPH_DEBUG or NSTRACE Date: Tue, 22 Aug 2017 10:23:36 +0200 Message-ID: References: NNTP-Posting-Host: blaine.gmane.org Mime-Version: 1.0 Content-Type: multipart/alternative; boundary="94eb2c0eb578d9359c0557534f6b" X-Trace: blaine.gmane.org 1503390275 21628 195.159.176.226 (22 Aug 2017 08:24:35 GMT) X-Complaints-To: usenet@blaine.gmane.org NNTP-Posting-Date: Tue, 22 Aug 2017 08:24:35 +0000 (UTC) Cc: Alan Third , Paul Eggert , emacs-devel , Noam Postavsky To: Keith David Bershatsky Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Tue Aug 22 10:24:29 2017 Return-path: Envelope-to: ged-emacs-devel@m.gmane.org Original-Received: from lists.gnu.org ([208.118.235.17]) by blaine.gmane.org with esmtp (Exim 4.84_2) (envelope-from ) id 1dk4U9-000577-0b for ged-emacs-devel@m.gmane.org; Tue, 22 Aug 2017 10:24:29 +0200 Original-Received: from localhost ([::1]:50246 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dk4UC-0003Rf-CE for ged-emacs-devel@m.gmane.org; Tue, 22 Aug 2017 04:24:32 -0400 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:38447) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dk4TM-0003Ld-KC for emacs-devel@gnu.org; Tue, 22 Aug 2017 04:23:46 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dk4TL-0007Ei-Di for emacs-devel@gnu.org; Tue, 22 Aug 2017 04:23:40 -0400 Original-Received: from mail-ua0-x236.google.com ([2607:f8b0:400c:c08::236]:34281) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1dk4TL-0007EN-7H for emacs-devel@gnu.org; Tue, 22 Aug 2017 04:23:39 -0400 Original-Received: by mail-ua0-x236.google.com with SMTP id d12so12149239uag.1 for ; Tue, 22 Aug 2017 01:23:37 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :cc; bh=fVAgJ1hufCOXvlsG8IYk77m9hyIeuLkaAkdkVvAvFMM=; b=i1rybD5JmwU4+Zb/LhC3EuQNCjFxWx/xAZ1xKuR6+qwtT0ah8WnDYZYbRHg1ULCs2L FbjhNmDnIKTR5kGSqcTz1F/zgUt8fVGcasBMy159hklwC+Au8liAX+gEcCIyNOuxltod 7cnPIyhEwDOGDjQtftDuOM9BkN49nN1UoPFR4D6OPryKLQbcwFP6/XPU9U9/SB7PxZ9+ e1n9p7LjXHxl69br3Czv8/1PknZouxm+sfEyT2bvtahmMfBdjk09S3UHgCuZj9L5Esj7 fmYir0VuBcFLwbA/+4TDpTjhz4glNyGx4T1mRFgdfpGI60ho+fiNYXu70anrkoqinyeU kbeQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:in-reply-to:references:from:date :message-id:subject:to:cc; bh=fVAgJ1hufCOXvlsG8IYk77m9hyIeuLkaAkdkVvAvFMM=; b=dw3rdFoa0qateaoC4LLTnkHqc9UHM19N/fNP3JtWKRWq9/KAFr0Yi8OBCHiP9HD1VN r1tAjngJQYwph0ilcR9fD2/y/GU3ykQDsIWQFGhXqaxid1cIQIIxmwM5SOrAG/d4m2So E1uvUqW+1fEvf0eds3YibUVQ/O6Q0wGLwinOxjAImzKmBSeJ826gr60wEtDCU9jnlr4F HqSyfaR17L27bDFob0OPC9YRgKiUQx5xFyhzD3r+ayF0Ch54Zb8CSOeiyA0FxbZAO2uE cAt95AUIm8iId33U/mBkf3FgCCtneDTFwNlP68b2d3CP9aq6WZYwHV9NveKu25hrsIYS hU0w== X-Gm-Message-State: AHYfb5goxr7MEcEEQoQ22emx9UYKxyrKisxWeHUp/I3ZgSelh46rY8yv Y1sUvY2bjKo3jiFrXaGRZhhxzJR+vA== X-Received: by 10.176.18.71 with SMTP id s7mr14048960uac.127.1503390217089; Tue, 22 Aug 2017 01:23:37 -0700 (PDT) Original-Received: by 10.31.171.3 with HTTP; Tue, 22 Aug 2017 01:23:36 -0700 (PDT) In-Reply-To: X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2607:f8b0:400c:c08::236 X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: "Emacs development discussions." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Original-Sender: "Emacs-devel" Xref: news.gmane.org gmane.emacs.devel:217678 Archived-At: --94eb2c0eb578d9359c0557534f6b Content-Type: text/plain; charset="UTF-8" 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 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 > > > > * * * > > > > 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 > > > > void > > example (CGFloat value) > > { > > char buf[DBL_BUFSIZE_BOUND]; > > NSTRACE ("float: %s", dtoastr (buf, sizeof buf, 0, 0, value)); > > } > > --94eb2c0eb578d9359c0557534f6b Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable
Hi!

I think(*) you can use "%a&quo= t; to print the hexadecimal representation of a floating point number. This= prints the floating point number exactly, down to the last bit in the mant= issa. It looks like=C2=A00x0.3p10, where 0x0.3 is the "significant&quo= t; part and "p10" the binary exponent, and it represents the numb= er 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 color= s use the same format). For example:

=C2=A0 =C2=A0 #define NSTRACE_F= MT_RGB "(R:%a G:%a B:%a)"

And another to push the argument= s:

=C2=A0 =C2=A0 #define NSTRACE_ARG_RGB(color) (color).redComponent= , (color).greenComponent, (color).blueComponent

With this, you shoul= d be able to print the color values ergonomically using:

=C2=A0 =C2= =A0 NSTRACE("The colors are " NSTRACE_FMT_RGB, NSTRACE_ARG_RGB([b= ackground_color colorUsingDefaultColorSpace]));

To make this even sh= orter, 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.

=C2=A0 =C2=A0 -- An= ders


On Tue, Aug 22, 2017 at 6:30 AM, Keith David Bershatsky <esq@lawli= st.com> wrote:
Thank you, P= aul, for the suggestion to use dtoastr.=C2=A0 I tried that and a few variat= ions, but got stuck because dtoastr returns an `int` and `%s` expects a `ch= ar` value.=C2=A0 Substituting `%s` for `%d` did not yield the correct resul= ts.

Keith

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
DATE:=C2=A0 [08-21-2017 16:55:08] <21 Aug 2017 16:55:08 -0700>
FROM:=C2=A0 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 3= 2-bit
> platforms where CGFloat is 'float', it would be easy to fix th= at if you
> like the idea.
>
> #include <ftoastr.h>
>
> void
> example (CGFloat value)
> {
>=C2=A0 =C2=A0 char buf[DBL_BUFSIZE_BOUND];
>=C2=A0 =C2=A0 NSTRACE ("float: %s", dtoastr (buf, sizeof buf,= 0, 0, value));
> }


--94eb2c0eb578d9359c0557534f6b--