[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Writing rational numbers
From: |
Kevin Ryde |
Subject: |
Re: Writing rational numbers |
Date: |
06 May 2001 05:49:56 +1000 |
User-agent: |
Gnus/5.0808 (Gnus v5.8.8) Emacs/20.5 |
Hans Aberg <address@hidden> writes:
>
> The first toggle, when set true, will write integers as 5/1, or when the
> second toggle is set true, as 5 0/1. The advantage of this format is that
> it can be combined with an input function that always can distinguish
> between integers and rational numbers. However, when I tried to write
> multivariate polynomials using this option, it did not look well (perhaps
> due to lack of experience with the printing style).
In the pipeline is a simple mpq_out_str (and mpq_get_str) giving
either "p/q" or just "p" as necessary. It'll be left to applications
to use mpz_out_str directly for "p/q" always.
> The second toggle, when set true, will write rational numbers of the form
> n p/q, where n, p, q are integers. (Here, n is dropped if 0. If n != 0,
> only n can be negative, and if n == 0, only p can be negative.) For example
> 22/7 will be written as 3 1/7, and -5/2 will be written as -2 1/2.
I'll put that on a list as a gmp_printf possibility, if/when that
routine ever gets done. Perhaps 3+1/7 or -2-1/2 would be possible
too, to avoid spaces in numbers.
> I gather a reading function may use similar toggles, but I use Flex to
> parse numbers, so I only made sure that my function could read n p/q
> formats, not bothering about the details (as the Flex parser will take care
> of that).
Also in the pipeline is an mpq_set_str which accepts either "p" or
"p/q". I don't think "n p/q" can work, since the p and q will be
parsed the same as mpz_set_str, which means all white space is ignored
(I'm not saying that's a good thing, but it's how it is at the
moment).