[Nickle]Printing of rationals

Keith Packard keithp@keithp.com
Tue, 10 Jul 2001 12:05:14 -0700


Around 13 o'clock on Jul 10, Carl Worth wrote:

> Now, the first thing I tried to do was to show off the fancy arbitrary
> precision rationals to my friend. Unfortunately, this is what I got:
> 
>	$ nickle
>	> 1/8! 
>	0.0000248{015873}
>	> 1/16!
>	4.7{79477332387385e-14

Expressions typed at the top level are displayed by calling the
builtin-function Command::display which takes a format and a value to
display, the format passed comes from the global variable "format", which
by default is set to:

	> format
	"%g"

The default output precision for "%g" is 14 places; this makes it a bit 
more reasonable for many calculations.  You can change this by changing 
the format value:

	> format="%.100g"
	"%.100g"
	> 1/16!
	0.000000000000047{7947733238738529743820749111754402759693764984770275775566780857786148791439796730802
	>

If you want rationals to be printed precisely, you can ask that all digits 
be printed, regardless of length (well, it actually stops at 10 million 
digits; perhaps that should be adjustable as well?):

	> format="%.-g"
	"%.-g"
	> 1/16!
	0.000000000000047{794773323873852974382074911175440275969376498477
	027577556678085778614879143979673080202180731281260381789482318582
	847683376783905884434984964085493186022286551387080487609588138688
	667789196889725990255090784191313291842392371492900593429693958794
	487895016995546096075196604297133397662498191598720699249799778900
	308000837101366201895302424402953503482604011704540805069905599006
	128106657207186307715408244508773609302709831810360910890011419111
	948212477313006413535514064614593715122815651916181016710117239217
	768318297418826519355619884720413820942921472022001122530223059323
	588424117524646625175725704826233926763027292127821228350328879429
	408529937630466730995831524932054032583133112233641334170434699535
	228635757736286836815937345037874138403238932339461439990540519641
	048741577842106942636043165143694244223344752445281545810646339746
	868847397947927048456148985249514350043450572551101651630752159852
	688953218053747154276254805355334455863556392656921757450857979958
	509059038159567260096360625461154561683662212762741863270963800064
	329164858265387365916466445566974667503768032868561969091069620170
	149270678371207471736572265672}
	> 

-keith