all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
* Re: How to use a float value with either GLYPH_DEBUG or NSTRACE
@ 2017-08-21 20:51 Keith David Bershatsky
  2017-08-21 21:30 ` Noam Postavsky
  0 siblings, 1 reply; 12+ messages in thread
From: Keith David Bershatsky @ 2017-08-21 20:51 UTC (permalink / raw)
  To: Alan Third; +Cc: emacs-devel

Thank you, Alan:

I had erroneously assumed that `%f` was only for adding/removing decimal places or rounding, rather than to show the approximate value of a `double` in this context.

I ran a few tests and am guessing that `%f` uses six (6) decimal places.  I understand that %f can be used to increase/decrease the number of decimal places.  However, this leaves me guessing exactly what the double looks like.  If the double is exactly 1.0, then it would be nice to see the same thing rather than 1.000000.  If the double is several decimal places, then I'd like to see the whole thing.

Then again, it is possible that the snippet in the opening thread is producing a double of exactly six (6) decimal places, but I do not know for sure if that is the case.

So the `%f` solution give me 99% of what I was looking for, which is certainly sufficient to handle this particular issue.  If you or anyone else have a way to print the exact value of whatever the double is (without adding/removing decimal places), an additional approach would be appreciated.

Keith

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

DATE:  [08-21-2017 13:07:56] <21 Aug 2017 21:07:56 +0100>
FROM:  Alan Third <alan@idiocy.org>
> 
> * * *
> 
> Is it not just like printf?
> 
>     NSTRACE("float: %f", var);
> 
> -- 
> Alan Third



^ permalink raw reply	[flat|nested] 12+ messages in thread
* Re: How to use a float value with either GLYPH_DEBUG or NSTRACE
@ 2017-08-22 17:04 Keith David Bershatsky
  0 siblings, 0 replies; 12+ messages in thread
From: Keith David Bershatsky @ 2017-08-22 17:04 UTC (permalink / raw)
  To: Anders Lindgren, Noam Postavsky; +Cc: Alan Third, Paul Eggert, emacs-devel

I have tested Paul's amended example provided by Noam, and can confirm that it works well.

I have also implemented the example of Anders, which works well without any changes needed.

Thank you all for teaching me how to get more out of the built-in trace debugging tools.

Greatly appreciated,

Keith



^ permalink raw reply	[flat|nested] 12+ messages in thread
* Re: How to use a float value with either GLYPH_DEBUG or NSTRACE
@ 2017-08-22  4:30 Keith David Bershatsky
  2017-08-22  8:23 ` Anders Lindgren
  0 siblings, 1 reply; 12+ messages in thread
From: Keith David Bershatsky @ 2017-08-22  4:30 UTC (permalink / raw)
  To: Paul Eggert; +Cc: Alan Third, Noam Postavsky, emacs-devel

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));
> }



^ permalink raw reply	[flat|nested] 12+ messages in thread
* Re: How to use a float value with either GLYPH_DEBUG or NSTRACE
@ 2017-08-21 21:45 Keith David Bershatsky
  0 siblings, 0 replies; 12+ messages in thread
From: Keith David Bershatsky @ 2017-08-21 21:45 UTC (permalink / raw)
  To: Noam Postavsky; +Cc: Alan Third, emacs-devel

Thank you, Noam:

Yes, that works nicely to eliminate the extra zeros and it also lets me see several decimal places when they have a value.

Thank you also for the link to the floating point conversions page.

Greatly appreciated,

Keith

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

DATE:  [08-21-2017 14:30:52] <21 Aug 2017 17:30:52 -0400>
FROM:  Noam Postavsky <npostavs@users.sourceforge.net>
> 
> * * *
> 
> I think `%.20g' should give you that (the max precision of double is
> about 17 decimal digits), although I would imagine that "the whole
> thing" is usually more than is really useful.
> 
> https://www.gnu.org/software/libc/manual/html_node/Floating_002dPoint-Conversions.html



^ permalink raw reply	[flat|nested] 12+ messages in thread
* How to use a float value with either GLYPH_DEBUG or NSTRACE
@ 2017-08-21 17:07 Keith David Bershatsky
  2017-08-21 20:07 ` Alan Third
  0 siblings, 1 reply; 12+ messages in thread
From: Keith David Bershatsky @ 2017-08-21 17:07 UTC (permalink / raw)
  To: Emacs Devel

The following snippet yields the correct the result.  However, I would like to see the float values for RED, BLUE, and GREEN in the terminal when running NSTRACE and/or GLYPH_DEBUG.  I believe that I am limited to things that FORMAT accepts, however, I cannot figure out how to incorporate a float value in a NSTRACE or/or GLYPH_DEBUG statement.

It would be greatly appreciated if someone could please give me an example of how to use a float value as an argument for either GLYPH_DEBUG or NSTRACE.

BACKGROUND:  I am working on my own feature requests (Emacs Bug #17684 and #22873).

  struct frame *f = XFRAME (WINDOW_FRAME (w));
  struct face *face;
  /* The default face, possibly remapped. */
  face = FACE_FROM_ID (f, lookup_basic_face (f, DEFAULT_FACE_ID));
  NSColor *background_color = ns_lookup_indexed_color (face->background, f);
  Lisp_Object color_vector;
  EmacsCGFloat red, green, blue, alpha, gray;
  char buf[1024];
  const char *str;
  if ([[background_color colorSpaceName] isEqualToString: NSNamedColorSpace])
      if ((str =[[background_color colorNameComponent] UTF8String]))
        {
          color_vector = build_string ((char *)str);
          goto done;
        }
    [[background_color colorUsingDefaultColorSpace]
        getRed: &red green: &green blue: &blue alpha: &alpha];
  if (red == green && red == blue)
    {
      [[background_color colorUsingColorSpaceName: NSCalibratedWhiteColorSpace]
            getWhite: &gray alpha: &alpha];
      snprintf (buf, sizeof (buf), "#%2.2lx%2.2lx%2.2lx",
                lrint (gray * 0xff), lrint (gray * 0xff), lrint (gray * 0xff));
      color_vector = build_string (buf);
      goto done;
    }
  snprintf (buf, sizeof (buf), "#%2.2lx%2.2lx%2.2lx",
            lrint (red*0xff), lrint (green*0xff), lrint (blue*0xff));
  color_vector = build_string (buf);
  done:
  NSTRACE_MSG ("BACKGROUND COLOR: %s", buf);


Thanks,

Keith



^ permalink raw reply	[flat|nested] 12+ messages in thread

end of thread, other threads:[~2017-08-22 17:04 UTC | newest]

Thread overview: 12+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2017-08-21 20:51 How to use a float value with either GLYPH_DEBUG or NSTRACE Keith David Bershatsky
2017-08-21 21:30 ` Noam Postavsky
2017-08-21 23:55   ` Paul Eggert
  -- strict thread matches above, loose matches on Subject: below --
2017-08-22 17:04 Keith David Bershatsky
2017-08-22  4:30 Keith David Bershatsky
2017-08-22  8:23 ` Anders Lindgren
2017-08-22 11:32   ` Noam Postavsky
2017-08-22 11:51     ` Anders Lindgren
2017-08-22 15:47     ` Paul Eggert
2017-08-21 21:45 Keith David Bershatsky
2017-08-21 17:07 Keith David Bershatsky
2017-08-21 20:07 ` Alan Third

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.