[ltk-user] Re: Problems with double floats

Tobias C. Rittweiler tcr at freebits.de
Sun Aug 12 08:46:09 UTC 2007


"Thomas F. Burdick" <tfb at ocf.berkeley.edu> writes:

> On 8/11/07, Tobias C. Rittweiler <tcr at freebits.de> wrote:
> >
> > Hi,
> >
> > maybe I'm missing something obvious, but LTK doesn't seem to work with
> > double-floats for me. For instance:
>
> >    (with-ltk ()
> >        (let ((c (make-canvas nil)))
> >          (pack c)
> >          (create-line c '(0 0 100 100d0))))
>
> You're not missing anything; at the moment Ltk is sending the PRINC
> representation of your numbers to Tk, which means Tk gets something
> like 100.0d0, which it doesn't understand.  This should be fixed in
> the Ltk release after next.

Yes, I've just discovered exactly that. May I ask how you intend to fix
it? Not setting *print-pretty* to NIL in LTK:FORMAT-WISH, and then doing
something like `(set-pprint-dispatch '(double-float) (formatter "~F"))'?

You probably also run the snippet with LTK:*DEBUG-TK* set to T (the
output is attached below in any case) --- there seems to be another kind
of problem that prevents LTK to handle the case gracefully, because as
you see below, the process gets stuck in some kind of finalizer loop
right when I exit the window.


> In the meantime, there are two work-arounds: either use single floats
> or set *read-default-float-format* to double-float.  I don't see the
> point in using double-floats to represent on-screen values, but maybe
> they're the results of calculations where double-floats are warranted,
> in which case the second alternative might be easier than coercing to
> single-floats.

They're results of calculations, indeed. Calculations that involve CL:PI
to be precise. (Note that CL:PI just happens to be of type DOUBLE-FLOAT
on SBCL, i.e. the same issue arises for numbers of type LONG-FLOAT.)


Thanks for your response, Thomas!

  -T.


LTK> (let ((*debug-tk* t))
       (with-ltk ()
	 (let ((c (make-canvas nil)))
	   (pack c)
	   (create-line c '(0 0 100 100d0)))))
package require Tk
proc escape {s} {regsub -all {\\} $s {\\\\} s1;regsub -all {"} $s1 {\"} s2;return $s2}
proc senddata {s} {puts "(:data [escape $s])";flush stdout}
proc senddatastring {s} {puts "(:data \"[escape $s]\")";flush stdout} 
proc senddatastrings {strings} {
                 puts "(:data ("
 	         foreach s $strings {
                     puts "\"[escape $s]\""
                     }
                 puts "))";flush stdout} 

proc sendevent {s x y keycode char width height root_x root_y mouse_button} {puts "(:event \"$s\" $x $y $keycode $char $width $height $root_x $root_y $mouse_button)"} 
proc callback {s} {puts "(:callback \"$s\")";flush stdout} 
proc callbackval {s val} {puts "(:callback \"$s\" $val)"} 
proc callbackstring {s val} {puts "(:callback \"$s\" \"[escape $val]\")"} 
canvas .w2 
pack .w2 -side top -fill none
senddata [.w2 create line 0 0 100 100.0]
read-data error: bad screen distance "100.0d0"
postponing event: NIL
postponing event: NIL
postponing event: NIL
postponing event: NIL
postponing event: NIL
postponing event: NIL
postponing event: NIL
postponing event: NIL
...
[C-c C-c]
exit
Error sending command to wish: Couldn't write to #<SB-SYS:FD-STREAM for "descriptor 7" {B9DB791}>: Broken pipeClosing wish stream: #<TWO-WAY-STREAM :INPUT-STREAM #<SB-SYS:FD-STREAM for "descriptor 8" {B9DC149}> :OUTPUT-STREAM #<SB-SYS:FD-STREAM for "descriptor 7" {B9DB791}>>
Closing wish stream: #<TWO-WAY-STREAM
                       :INPUT-STREAM #<SB-SYS:FD-STREAM for "descriptor 8" {B9DC149}>
                       :OUTPUT-STREAM #<SB-SYS:FD-STREAM for "descriptor 7" {B9DB791}>>




More information about the ltk-user mailing list