[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Writing rational numbers
From: |
Hans Aberg |
Subject: |
Writing rational numbers |
Date: |
Thu, 3 May 2001 20:09:40 +0200 |
In case one would add writing routines to the GMP rational numbers, when
experimented with it, I found two toggles:
Always write "/": false, true.
Write integral part: false, true.
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).
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 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).
Hans Aberg
- Writing rational numbers,
Hans Aberg <=