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

Re: Simpe Gwydion question



hebisch@math.uni.wroc.pl (Waldek Hebisch) wrote in message news:<aghjiv$lt6$1@panorama.wcss.wroc.pl>...

> -- How one prints a floating point number.  I was able 
>    to find examples of format, but only for integers 

Use the %= control sequence with format.

  format-out("%=", 2.3 * 9.443341) => 21.7196843d0

For the guts: gd/src/common/print/print.dylan


> -- How one conwerts between numbers and strings (both integers 
>    and floating point)

Use the common-extensions library.  It has float-to-string, integer-to-string,
string-to-integer, and number-to-string.


> -- How one declares an array of doubles.  Currently I use generic
>    array and the program is VERY slow. I tried 
>    limited(<vector>, of: <double-float>)
>    but then the program died at runtime.

How did it die?  Can you post the code?

I tried this (which worked):

define constant <double-vector> = limited(<vector>, of: <double-float>);

define function vector-foo() => ()
  let dvec :: <double-vector> = make(<double-vector>, size: 10000, fill: 0.0);

  for (i from 0 below dvec.size)
    // i wanted to fill this with random numbers, but i couldn't find
    // random() in common-extensions.
    dvec[i] := i * 1.64;
  end for;

  for (i from 0 below dvec.size)
    format-out("%d %=\n", i, dvec[i])
  end for;
end function vector-foo;

With size: 10000000 and without the format-out loop, it still took 13 seconds
on my 800MHz Athlon box.