Path: csiph.com!eternal-september.org!feeder.eternal-september.org!reader01.eternal-september.org!.POSTED!not-for-mail From: Keith Thompson Newsgroups: comp.lang.c Subject: Re: Big integers Date: Wed, 05 Dec 2018 13:46:11 -0800 Organization: None to speak of Lines: 31 Message-ID: References: <01c809d8-12f2-4755-8207-a000f1d6c9c1@googlegroups.com> <%VyND.512769$p%6.229167@fx26.am4> Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit Injection-Info: reader01.eternal-september.org; posting-host="0d78d54efc88e0a4fac1f9fdf2ba2e14"; logging-data="28836"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/X8pWb3/YL8lZKuRAlD992" User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/23.1 (gnu/linux) Cancel-Lock: sha1:MouMrdEmXw4/Z7IRYIMs0h8hn7c= sha1:g4YCY6fAa4g1xwYuT5+LkL4AiII= Xref: csiph.com comp.lang.c:138557 jacob navia writes: > Le 04/12/2018 à 18:35, Bart a écrit : > > An extended precision floating > > point library would also be intriguing to > > write. But it can't be arbitrary precision. (How many digits to > > represent 1/3 exactly in either binary or decimal?) > I have written one, based on the work of Stephen L Moshier, in x86 asm > and arm64 asm. It has aroud the same speed as GMP... > The layout is as follows: > > Each number is 64 bytes, where the first 32 are the sign (I know is > wasteful but it is faster than using only one bit) the, the next 32 are > the exponent (biased) and then 7 64 bit integers with the mantissa. > > All functions of the C standard library are provided using this format So you have a sign, a 32-bit exponent, and a 448-bit mantissa. Unless I'm missing something, that still can't represent 1/3 exactly (though it can approximate it much more closely than smaller formats can). To represent 1/3 *exactly*, you need either trinary (which can't represent 1/5 or 1/7 exactly, or even 1/2) or some kind of numerator/denominator representation. -- Keith Thompson (The_Other_Keith) kst@mib.org Will write code for food. "We must do something. This is something. Therefore, we must do this." -- Antony Jay and Jonathan Lynn, "Yes Minister"