14 Mar 2003 11:07:16 -0500

Related articles |
---|

rational to floating point thant@acm.org (Thant Tessman) (2003-03-09) |

Re: rational to floating point chase@theworld.com (David Chase) (2003-03-14) |

Re: rational to floating point nmm1@cus.cam.ac.uk (2003-03-14) |

Re: rational to floating point thant@acm.org (Thant Tessman) (2003-03-14) |

Re: rational to floating point joachim_d@gmx.de (Joachim Durchholz) (2003-03-14) |

Re: rational to floating point ajo@andrew.cmu.edu (Arthur J. O'Dwyer) (2003-03-14) |

Re: rational to floating point gah@ugcs.caltech.edu (Glen Herrmannsfeldt) (2003-03-14) |

Re: rational to floating point tmk@netvision.net.il (2003-03-14) |

Re: rational to floating point Peter-Lawrence.Montgomery@cwi.nl (2003-03-14) |

[1 later articles] |

From: | nmm1@cus.cam.ac.uk (Nick Maclaren) |

Newsgroups: | comp.compilers |

Date: | 14 Mar 2003 11:07:16 -0500 |

Organization: | University of Cambridge, England |

References: | 03-03-035 |

Keywords: | arithmetic |

Posted-Date: | 14 Mar 2003 11:07:16 EST |

Thant Tessman <thant@acm.org> writes:

|>

|> I've been writing an interpreter for a functional programming language

|> in C++. One of the datatypes it supports is an arbitrary-precision

|> rational number type. Currently the interpreter displays rational

|> numbers as the ratio of two integers. I'd like it to display rational

|> numbers as floating-point numbers whenever the conversion to floating

|> point won't produce an infinite (repeating) stream of digits.

|>

|> The question is: Under what conditions will a rational number produce

|> an infinite stream of digits for a given base? What I've come up with

|> is this:

Assuming that the number has been reduced to its simplest terms

(i.e. with all common factors removed), then it will be whenever

the denominator contains any prime factor other than 2 and 5.

But you may not find this a good idea, even for numbers that do

expand directly, because of their resulting length. Expand out

1/1024, for example.

Regards,

Nick Maclaren,

University of Cambridge Computing Service,

New Museums Site, Pembroke Street, Cambridge CB2 3QH, England.

Email: nmm1@cam.ac.uk

Tel.: +44 1223 334761 Fax: +44 1223 334679

Post a followup to this message

Return to the
comp.compilers page.

Search the
comp.compilers archives again.