9fans - fans of the OS Plan 9 from Bell Labs
 help / color / mirror / Atom feed
* Re: [9fans] double->string conversion
@ 2001-10-29 14:05 rog
  0 siblings, 0 replies; 5+ messages in thread
From: rog @ 2001-10-29 14:05 UTC (permalink / raw)
  To: 9fans

> doesn't print("%g") do it?

nope. for example, 

	double xmin, xmax;
	[...]
	print("%g %g; difference: %g\n", xmin, xmax, xmax - xmin);
	print("hex: %ullx %ullx\n", *(vlong *)&xmin, *(vlong *)&xmax);

prints:

	-.9909985 -.9909985 difference: 4.551914e-15
	hex: bfefb6429008c02c bfefb6429008c003

> The %f, %g, strtod functions in both Inferno and 3rd edition Plan 9
> are intended to be accurate.   (The version in 2nd edition is known
> to be less exact.)

what parameters does the %g conversion need to ensure
that a later strtod will produce the same value?

  rog.



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

* Re: [9fans] double->string conversion
@ 2001-10-29 22:52 Eric Grosse
  0 siblings, 0 replies; 5+ messages in thread
From: Eric Grosse @ 2001-10-29 22:52 UTC (permalink / raw)
  To: 9fans

> what parameters does the %g conversion need to ensure
> that a later strtod will produce the same value?

%.17g is enough.

http://plan9.bell-labs.com/netlib/fp/g_fmt.c.gz gives a
shorter string, in general, that also promises to exactly
reproduce the starting binary value.

Eric


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

* Re: [9fans] double->string conversion
@ 2001-10-26 20:45 Eric Grosse
  0 siblings, 0 replies; 5+ messages in thread
From: Eric Grosse @ 2001-10-26 20:45 UTC (permalink / raw)
  To: 9fans

The %f, %g, strtod functions in both Inferno and 3rd edition Plan 9
are intended to be accurate.   (The version in 2nd edition is known
to be less exact.)

The one in Inferno comes from David Gay and is the more heavily tested;
see http://plan9.bell-labs.com/netlib/fp/.

The one in Plan 9 (/sys/src/libc/port/fltconv.c and strtod.c) is by
Ken Thompson and should give the same conversion.  It is shorter but
probably not as fast.   If you find accuracy problems with either
one, please let me know.

Eric


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

* [9fans] double->string conversion
@ 2001-10-26 20:37 rog
  0 siblings, 0 replies; 5+ messages in thread
From: rog @ 2001-10-26 20:37 UTC (permalink / raw)
  To: 9fans

is there a plan 9 interface to an accurate float to string
conversion routine, like inferno's sys->sprint("%g")?



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

* Re: [9fans] double->string conversion
@ 2001-10-26 20:27 Russ Cox
  0 siblings, 0 replies; 5+ messages in thread
From: Russ Cox @ 2001-10-26 20:27 UTC (permalink / raw)
  To: 9fans

> is there a plan 9 interface to an accurate float to string
> conversion routine, like inferno's sys->sprint("%g")?

doesn't print("%g") do it?



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

end of thread, other threads:[~2001-10-29 22:52 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2001-10-29 14:05 [9fans] double->string conversion rog
  -- strict thread matches above, loose matches on Subject: below --
2001-10-29 22:52 Eric Grosse
2001-10-26 20:45 Eric Grosse
2001-10-26 20:37 rog
2001-10-26 20:27 Russ Cox

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).