<?xml version="1.0"?>
<rss version="2.0">
	<channel>
		<title>Looking for math library</title>
		<link>http://www.allegro.cc/forums/view/607410</link>
		<description>Allegro.cc Forum Thread</description>
		<webMaster>matthew@allegro.cc (Matthew Leverton)</webMaster>
		<lastBuildDate>Sun, 29 May 2011 04:35:42 +0000</lastBuildDate>
	</channel>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>I&#39;m looking for a decent math library. It has to satisfy the following conditions :</p><p>1) When scanned, &quot;#.#&quot; has to equal #.# - ie... &quot;5.1&quot; has to equal 5.1 when scanned from a string. Because currently if I use sscanf on &quot;5.1&quot; to get a double and then printf the double back out with high precision, it is 5.0999999999999996 instead of 5.1, and this occurs far too often with other numbers as well, even if it is only off by 4e-16 or so. I want to be able to move from string to double and back without losing any precision.</p><p>2) It should support at least as many math functions as the C standard library.</p><p>3) C or C++ only.</p><p>4) Non GPL if possible, but maybe you can convince me otherwise if <br />a) My code doesn&#39;t have to be GPL too.<br />b) I&#39;m not <i>forced</i> to release all of my source code, even if I might anyway.</p><p>5) Optional - extra features?</p><p>I looked at <a href="http://en.wikipedia.org/wiki/List_of_numerical_libraries">The wikipedia list article of numerical libraries</a>, but about the only thing that looked good at first glance was the <a href="http://gmplib.org/">GNU MultiPrecision Library</a>. The <a href="http://www.gnu.org/software/gsl/">GNU Scientific Library</a> doesn&#39;t seem to offer precision greater than doubles do, only a truckload of math functions.</p><p>The problem with GMP is that it uses the LGPL, and I still haven&#39;t wrapped my head around what you can and can&#39;t do with the (L)GPL. I wish there was a (L)GPL for dummies guide around somewhere. <img src="http://www.allegro.cc/forums/smileys/tongue.gif" alt=":P" /></p><p>So, any recommendations / experience to share with me on this matter?
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Edgar Reynaldo)</author>
		<pubDate>Mon, 23 May 2011 10:26:06 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><div class="quote_container"><div class="title"><a href="http://www.allegro.cc/forums/thread/607410/918550#target">Edgar Reynaldo</a> said:</div><div class="quote"><p>
I want to be able to move from string to double and back without losing any precision.
</p></div></div><p>
This is impossible. You need to have decimal fraction storage to do that, and double does not provide that.</p><p>I only know of GMP and GSL too, but generally I&#39;ve never needed the additional precision of the first.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (SiegeLord)</author>
		<pubDate>Mon, 23 May 2011 10:31:43 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>You won&#39;t have a problem with LGPL libraries corrupting your source code as long as you dynamically link against them.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Matthew Leverton)</author>
		<pubDate>Mon, 23 May 2011 10:37:22 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><div class="quote_container"><div class="title"><a href="http://www.allegro.cc/forums/thread/607410/918550#target">Edgar Reynaldo</a> said:</div><div class="quote"><p> Because currently if I use sscanf on &quot;5.1&quot; to get a double and then printf the double back out with high precision, it is 5.0999999999999996 instead of 5.1,</p></div></div><div class="source-code snippet"><div class="inner"><pre><span class="p">#include &lt;stdio.h&gt;</span>

<span class="k1">double</span> f<span class="k2">;</span>
<span class="k1">int</span> i<span class="k2">;</span>

<span class="k1">int</span> main<span class="k2">(</span><span class="k1">void</span><span class="k2">)</span>
<span class="k2">{</span>
  <span class="k1">for</span><span class="k2">(</span>i<span class="k3">=</span><span class="n">0</span><span class="k2">;</span>i<span class="k3">&lt;</span><span class="n">100</span><span class="k2">;</span>i<span class="k3">+</span><span class="k3">+</span><span class="k2">)</span>
  <span class="k2">{</span>
    <a href="http://www.delorie.com/djgpp/doc/libc/libc_624.html" target="_blank">printf</a><span class="k2">(</span><span class="s">"%0.1lf %lf\n"</span>,f,f<span class="k2">)</span><span class="k2">;</span>  <span class="c">//print the single decimal place version followed by the ordinary version.</span>
    f <span class="k3">+</span><span class="k3">=</span> <span class="n">0</span>.<span class="n">11111</span><span class="k2">;</span>
  <span class="k2">}</span>
  <span class="k1">return</span> <span class="n">0</span><span class="k2">;</span>
<span class="k2">}</span>
</pre></div></div><p>
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Arthur Kalliokoski)</author>
		<pubDate>Mon, 23 May 2011 10:49:04 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>I love <a href="http://glm.g-truc.net/">this library</a>, even when I&#39;m not programming OpenGL. It&#39;s just great all around.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (decepto)</author>
		<pubDate>Mon, 23 May 2011 10:57:36 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><div class="quote_container"><div class="title"><a href="http://www.allegro.cc/forums/thread/607410/918551#target">SiegeLord</a> said:</div><div class="quote"><p>
This is impossible. You need to have decimal fraction storage to do that, and double does not provide that.
</p></div></div><p>
I know double doesn&#39;t do that, and that was kind of the point.</p><div class="quote_container"><div class="title"><a href="http://www.allegro.cc/forums/thread/607410/918552#target">Matthew Leverton</a> said:</div><div class="quote"><p>
You won&#39;t have a problem with LGPL libraries corrupting your source code as long as you dynamically link against them.
</p></div></div><p>
Dynamic linking is fine with me. Am I supposed to mention the library and provide a copy of the GPL and LGPL along with it? Can I just provide a link to the GPL, LGPL, and the url of the library used?</p><p>@Arthur Kalliokoski<br />I don&#39;t really know what you are trying to say with that code. Using a precision specifier with printf only allows you to specify the number of digits after the decimal point, not the actual number of significant digits. Ie 12.3 has 3 significant digits, not 1. It also does rounding, which I want to minimize as much as possible.</p><div class="quote_container"><div class="title"><a href="http://www.allegro.cc/forums/thread/607410/918554#target">decepto</a> said:</div><div class="quote"><p>
I love this library [glm.g-truc.net], even when I&#39;m not programming OpenGL. It&#39;s just great all around.
</p></div></div><p>

It looks decent to start off, but there&#39;s no guarantee of precision with their two high precision data types :
</p><div class="quote_container"><div class="title"><a href="http://glm.g-truc.net/api-0.9.2/a00236.html#ga6e95694987ba35af6f736638be39626a">precision types</a> said:</div><div class="quote"><p>
typedef highp_float_t highp_float</p><p>High precision floating-point numbers.</p><p>There is no guarantee on the actual precision. From GLSL 1.30.8 specification</p><p>Definition at line 54 of file type_float.hpp.<br />typedef detail::highp_int_t highp_int</p><p>High precision signed integer.</p><p>There is no guarantee on the actual precision. From GLSL 1.30.8 specification.</p><p>Definition at line 62 of file type_int.hpp.
</p></div></div><p>

What I want most is to be able to have a number string convert to an exactly corresponding decimal data type and back again. I can limit the precision later if necessary.</p><p>The <a href="http://speleotrove.com/decimal/">decNumber library</a> is looking good too, except for the GPL bit. If I use a GPL library in my program, is my program then automatically bound by the GPL as well?
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Edgar Reynaldo)</author>
		<pubDate>Mon, 23 May 2011 12:15:07 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><div class="quote_container"><div class="title"><a href="http://www.allegro.cc/forums/thread/607410/918557#target">Edgar Reynaldo</a> said:</div><div class="quote"><p> Using a precision specifier with printf only allows you to specify the number of digits after the decimal point, not the actual number of significant digits. Ie 12.3 has 3 significant digits, not 1. It also does rounding, which I want to minimize as much as possible.</p></div></div><p>You want to truncate digits?  Why?  If you want to eliminate rounding, multiply by the power of 10 you want to have the precision up to, floor() it, then divide again.<br />Or you could simply sprintf this number to a buffer, use strchr() to find the decimal point, use the index to the sought number for strcpy, etc.  Sure, it&#39;d be slower than pure math operations, but a library would slow things down as well.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Arthur Kalliokoski)</author>
		<pubDate>Mon, 23 May 2011 12:22:40 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><div class="quote_container"><div class="title"><a href="http://www.allegro.cc/forums/thread/607410/918557#target">Edgar Reynaldo</a> said:</div><div class="quote"><p>
If I use a GPL library in my program, is my program then automatically bound by the GPL as well?
</p></div></div><p>
Yes, you have to publish your source code as well under GPL. GPL is infectious. </p><p>When I found this: <a href="http://en.wikipedia.org/wiki/Arbitrary-precision_arithmetic">http://en.wikipedia.org/wiki/Arbitrary-precision_arithmetic</a> I was surprised how many such libraries there are... I have no experiences with any of them, however.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (tobing)</author>
		<pubDate>Mon, 23 May 2011 12:22:44 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>I have a 32 bit assembler arbitrary precision library you can have if you want, but I haven&#39;t been motivated enough to finish the 64 bit version.  To convert to assembly code for Windows, you&#39;d have to add an underscore prefix to the global namespaces.  I never did quite finish the transcendental functions either, but it does the fourbanger calculator stuff just fine, as well as print to ascii buffers and scan from ascii buffers.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Arthur Kalliokoski)</author>
		<pubDate>Mon, 23 May 2011 12:25:13 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>You need to tell us what you want this for, because most likely you don&#39;t actually know what you really want; it is very unlikely that you need a fully blown Decimal library for whatever it is you are doing.  Chances are that all you really need is to write your own double.ToString() method.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (james_lohr)</author>
		<pubDate>Mon, 23 May 2011 12:49:13 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><div class="quote_container"><div class="title"><a href="http://www.allegro.cc/forums/thread/607410/918558#target">Arthur Kalliokoski</a> said:</div><div class="quote"><p>
You want to truncate digits?  Why?  If you want to eliminate rounding, multiply by the power of 10 you want to have the precision up to, floor() it, then divide again.<br />Or you could simply sprintf this number to a buffer, use strchr() to find the decimal point, use the index to the sought number for strcpy, etc.  Sure, it&#39;d be slower than pure math operations, but a library would slow things down as well.
</p></div></div><p>
No, I said I want to minimize rounding - ie maintain precision up to an arbitrary point, maybe around 30 significant digits or so. Multiplying and dividing by 10 won&#39;t help fix the failure in precision of statements like 0.1 or 1/10.</p><p>Also, super speed is not essential in this application. It won&#39;t be computationally expensive over long periods of time.</p><div class="quote_container"><div class="title">Tobing said:</div><div class="quote"><p>
Yes, you have to publish your source code as well under GPL. GPL is infectious. 
</p></div></div><p>
&lt;runs for antibiotics&gt;</p><div class="quote_container"><div class="title"><a href="http://www.allegro.cc/forums/thread/607410/918560#target">Arthur Kalliokoski</a> said:</div><div class="quote"><p>
I have a 32 bit assembler arbitrary precision library you can have if you want, but I haven&#39;t been motivated enough to finish the 64 bit version.  To convert to assembly code for Windows, you&#39;d have to add an underscore prefix to the global namespaces.  I never did quite finish the transcendental functions either, but it does the fourbanger calculator stuff just fine, as well as print to ascii buffers and scan from ascii buffers.
</p></div></div><p>
I appreciate the offer, but I&#39;m going to need trig functions.</p><div class="quote_container"><div class="title"><a href="http://www.allegro.cc/forums/thread/607410/918561#target">James Lohr</a> said:</div><div class="quote"><p>
You need to tell us what you want this for, because most likely you don&#39;t actually know what you really want; it is very unlikely that you need a fully blown Decimal library for whatever it is you are doing.  Chances are that all you really need is to write your own double.ToString() method.
</p></div></div><p>
I&#39;ve already written a FormatDouble function, and it works fine. It retains the maximum amount of precision available from a double and strips leading and trailing zeros and optimizes the exponent for string length consideration.</p><p>What I&#39;m using it for is a console/plotter program that lets you enter equations as strings and then evaluate / simplify / derive / integrate? / plot them.</p><p>The LUA interpreter has better precision than a C++ double - it doesn&#39;t have any problem with 5.1 or 0.1, or most other common (relatively small) numbers and has precision of somewhere around 14 digits.</p><p>BTW, keep comments like &#39;I don&#39;t actually know what I really want&#39; to yourself. I&#39;ve already stated several times that I want more precision than doubles afford, and I want perfect string to decimal data type and back to string conversions.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Edgar Reynaldo)</author>
		<pubDate>Mon, 23 May 2011 13:21:18 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>The restrictions of LGPL are super-light. If you don&#39;t need modify the &quot;official&quot; DLL, you only need to provide a readme like this one:</p><div class="quote_container"><div class="title">doc/README-SDL.txt said:</div><div class="quote"><p>The following file:</p><p>	SDL.dll</p><p>is the runtime environment for the SDL library.</p><p>The Simple DirectMedia Layer (SDL for short) is a cross-platfrom library<br />designed to make it easy to write multi-media software, such as games and<br />emulators.</p><p>The Simple DirectMedia Layer library source code is available from:<br /><a href="http://www.libsdl.org/">http://www.libsdl.org/</a></p><p>This library is distributed under the terms of the GNU LGPL license:<br /><a href="http://www.gnu.org/copyleft/lesser.html">http://www.gnu.org/copyleft/lesser.html</a></p></div></div><p>

A little more complex example where I had to compile the DLL myself: since I didn&#39;t have to modifiy the sources, I simply point to the specific versions used :
</p><div class="quote_container"><div class="title">doc/README-SDL_image.txt said:</div><div class="quote"><p>The following file</p><p>	SDL_image.dll</p><p>is the runtime environment for the library SDL_image 1.2.10 by Sam Lantiga and Mattias Engdegård.</p><p>This library is distributed under the terms of the GNU LGPL license:<br /><a href="http://www.gnu.org/copyleft/lesser.html">http://www.gnu.org/copyleft/lesser.html</a></p><p>The source is available from the libraries page at the SDL website:<br /><a href="http://www.libsdl.org/">http://www.libsdl.org/</a></p><p>=========================</p><p>Compiled by yrizoud on 16/06/2010 with static builds of :<br />	libjpeg (JPEG library <a href="http://www.ijg.org/">http://www.ijg.org/</a> release 6b of 27-Mar-1998 : jpegsr6.zip)<br />	libtiff (TIFF library <a href="ftp://ftp.sgi.com/graphics/tiff/">ftp://ftp.sgi.com/graphics/tiff/</a> : tiff-v3.4-tar.gz)<br />And dynamic version of :<br />	libpng (<a href="http://www.libpng.org/pub/png/libpng.html">http://www.libpng.org/pub/png/libpng.html</a>) v1.4.2 --&gt; libpng14-14.dll requirement</p></div></div><p>
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Audric)</author>
		<pubDate>Mon, 23 May 2011 14:22:01 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>@Audric<br />That sounds reasonable enough.</p><p>The <a href="http://www.tc.umn.edu/~ringx004/mapm-main.html">MAPM library</a> is looking pretty good so far - it has most of the standard C math functions implemented and supports arbitrary precision math as well as conversion to and from c strings.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Edgar Reynaldo)</author>
		<pubDate>Mon, 23 May 2011 14:44:25 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>It makes it all too apparent what a dated language C++ is; Java has had BigDecimal for over a decade, and &quot;decimal&quot; is a basic type in C#.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (james_lohr)</author>
		<pubDate>Mon, 23 May 2011 23:48:48 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><div class="quote_container"><div class="title"><a href="http://www.allegro.cc/forums/thread/607410/918617#target">James Lohr</a> said:</div><div class="quote"><p>It makes it all too apparent what a dated language C++ is; Java has had BigDecimal for over a decade, and &quot;decimal&quot; is a basic type in C#.</p></div></div><p>
Except it isn&#39;t a basic type. It may be built-in to the language, but the CPU/FPU doesn&#39;t handle it directly. Software has to break it down, do the work, then reconstruct it.</p><p>C/C++&#39;s basic types are what the processor deals with. You don&#39;t even get float and double if your target machine doesn&#39;t have an FPU (unless your compiler offers FPU emulation, but that&#39;s not required as part of the language).</p><p>At most, it could be part of libc/libstdc++, but there are already libraries which implement it just fine.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Kitty Cat)</author>
		<pubDate>Tue, 24 May 2011 01:08:10 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>IIRC, the lcc-win32 compiler has arbitrary precision arithmetic, but lcc-win32 is slow and you can&#39;t use it for commercial programs.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Arthur Kalliokoski)</author>
		<pubDate>Tue, 24 May 2011 01:10:57 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><div class="quote_container"><div class="title"><a href="http://www.allegro.cc/forums/thread/607410/918550#target">Edgar Reynaldo</a> said:</div><div class="quote"><p>1) When scanned, &quot;#.#&quot; has to equal #.# - ie... &quot;5.1&quot; has to equal 5.1 when scanned from a string. Because currently if I use sscanf on &quot;5.1&quot; to get a double and then printf the double back out with high precision, it is 5.0999999999999996 instead of 5.1, and this occurs far too often with other numbers as well, even if it is only off by 4e-16 or so. I want to be able to move from string to double and back without losing any precision.</p></div></div><p>

I don&#39;t think you should ask for something like that without specifying what your precision requirements are.  </p><p>If you only care about destringifaction+stringification not producing the original value, simply limiting every decimal stringification to 14 digits meets your requirements well over a fairly wide range of numbers, though that&#39;s actually a <b>decrease</b> in precision.  </p><p>On the other hand if you need purely decimal math, that&#39;s a very different thing (though it would solve the above problem as long as all stringifications were to decimal).  Likewise if you need infinite precision.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (orz)</author>
		<pubDate>Tue, 24 May 2011 01:54:20 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><div class="quote_container"><div class="title"><a href="http://www.allegro.cc/forums/thread/607410/918617#target">James Lohr</a> said:</div><div class="quote"><p>Java has had BigDecimal for over a decade, and &quot;decimal&quot; is a basic type in C#.</p></div></div><p>
Since computers use binary rather than decimal, I would consider that a rather useless feature.<br />I mean, sure, you can&#39;t express decimal farctions exactly in a binary representation, but they&#39;re both equally arbitrary anyway. You can&#39;t express a fraction of a third exactly in either, for instance.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Evert)</author>
		<pubDate>Tue, 24 May 2011 02:27:14 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><div class="quote_container"><div class="title"><a href="http://www.allegro.cc/forums/thread/607410/918632#target">orz</a> said:</div><div class="quote"><p>If you only care about destringifaction+stringification not producing the original value, simply limiting every decimal stringification to 14 digits meets your requirements well over a fairly wide range of numbers, though that&#39;s actually a decrease in precision.</p></div></div><p>
Or you can use %a (C99), which uses a hexadecimal notation for floating-point values. The default precision allows you to distinguish between two double values.
</p><pre>a, A   (C99; not in SUSv2) For a conversion, the double argument  is  converted  to
       hexadecimal notation (using the letters abcdef) in the style [-]0xh.hhhhp±d;
       for A conversion the prefix 0X, the letters ABCDEF, and the exponent separa‐
       tor P is used.  There is one hexadecimal digit before the decimal point, and
       the number of digits after it is equal to the precision.  The default preci‐
       sion suffices for an exact representation of the value if an exact represen‐
       tation in base 2 exists and otherwise is sufficiently large  to  distinguish
       values  of  type  double.  The digit before the decimal point is unspecified
       for nonnormalized numbers, and nonzero but otherwise unspecified for normal‐
       ized numbers.</pre><p>
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Kitty Cat)</author>
		<pubDate>Tue, 24 May 2011 02:34:56 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><div class="quote_container"><div class="title"><a href="http://www.allegro.cc/forums/thread/607410/918646#target">Evert</a> said:</div><div class="quote"><p>
I mean, sure, you can&#39;t express decimal farctions exactly in a binary representation, but they&#39;re both equally arbitrary anyway. You can&#39;t express a fraction of a third exactly in either, for instan
</p></div></div><p>

...let alone irrational numbers.</p><p>What about the gnu big number library ? Not sure if that would help.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (William Labbett)</author>
		<pubDate>Tue, 24 May 2011 02:49:29 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>The decimal type in C# is not for mathematicians, but accountants.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Audric)</author>
		<pubDate>Tue, 24 May 2011 03:41:08 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><div class="quote_container"><div class="title"><a href="http://www.allegro.cc/forums/thread/607410/918682#target">Audric</a> said:</div><div class="quote"><p> The decimal type in C# is not for mathematicians, but accountants.</p></div></div><p>Isn&#39;t the &#39;#.#&#39; specifier from COBOL?  It&#39;s meant for accountants and $PHB&#39;s.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Arthur Kalliokoski)</author>
		<pubDate>Tue, 24 May 2011 03:46:00 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><div class="quote_container"><div class="title"><a href="http://www.allegro.cc/forums/thread/607410/918632#target">orz</a> said:</div><div class="quote"><p>
I don&#39;t think you should ask for something like that without specifying what your precision requirements are.
</p></div></div><p>
My precision requirements are that string numbers have an exact representation when converted to data. With my current implementation using doubles, my command line calculator / function parser is too stupid to return 51 for 5.1/0.1. That&#39;s just not acceptable to me, nor should it be acceptable to anyone using a calculator program.</p><div class="quote_container"><div class="title">Kitty Cat said:</div><div class="quote"><p>
Or you can use %a (C99), which uses a hexadecimal notation for floating-point values. The default precision allows you to distinguish between two double values.
</p><div class="quote_container"><div class="title"><a href="http://www.allegro.cc/forums/thread/607410/918650#target">Kitty Cat</a> said:</div><div class="quote"><p>
The default precision suffices for an exact representation of the value if an exact representation in base 2 exists and otherwise is sufficiently large to distinguish values of type double.
</p></div></div><p>
</p></div></div><p>
This is the basis of the problem - most base 2 floating point representations are just incapable of representing decimals correctly. If they used base 2 to represent the numerals and used a separate number to represent the decimal point, then there shouldn&#39;t ever be a problem with it, but you can&#39;t represent every number with powers of 1/2.</p><div class="quote_container"><div class="title"><a href="http://www.allegro.cc/forums/thread/607410/918660#target">William Labbett</a> said:</div><div class="quote"><p>
What about the gnu big number library ? Not sure if that would help.
</p></div></div><p>
That&#39;s the same thing as the GNU Multi Precision library. I&#39;m looking into it.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Edgar Reynaldo)</author>
		<pubDate>Wed, 25 May 2011 10:49:41 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>Theres <a href="http://www.cdc.informatik.tu-darmstadt.de/TI/LiDIA/">LIDIA</a> but I&#39;m not sure what it could do for you.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (verthex)</author>
		<pubDate>Wed, 25 May 2011 11:06:01 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><div class="quote_container"><div class="title"><a href="http://www.allegro.cc/forums/thread/607410/918864#target">Edgar Reynaldo</a> said:</div><div class="quote"><p> With my current implementation using doubles, my command line calculator / function parser is too stupid to return 51 for 5.1/0.1.</p></div></div><div class="source-code"><div class="toolbar"><span class="button numbers"><b>#</b></span><span class="button select">Select</span><span class="button expand">Expand</span></div><div class="inner"><span class="number">  1</span><span class="p">#include &lt;stdio.h&gt;</span>
<span class="number">  2</span><span class="p">#include &lt;stdlib.h&gt;</span>
<span class="number">  3</span><span class="p">#include &lt;errno.h&gt;</span>
<span class="number">  4</span>
<span class="number">  5</span><span class="k1">int</span> main<span class="k2">(</span><span class="k1">int</span> argc, <span class="k1">char</span> <span class="k3">*</span><span class="k3">*</span>argv<span class="k2">)</span>
<span class="number">  6</span><span class="k2">{</span>
<span class="number">  7</span>  <span class="k1">double</span> parm1<span class="k2">;</span>
<span class="number">  8</span>  <span class="k1">double</span> parm2<span class="k2">;</span>
<span class="number">  9</span>  <span class="k1">double</span> result<span class="k2">;</span>
<span class="number"> 10</span>  <span class="k1">int</span> intresult<span class="k2">;</span>
<span class="number"> 11</span>  <span class="k1">int</span> <span class="k1">operator</span><span class="k2">;</span>
<span class="number"> 12</span>  <span class="k1">char</span> <span class="k3">*</span>end1<span class="k2">;</span>
<span class="number"> 13</span>  
<span class="number"> 14</span>  <span class="k1">if</span><span class="k2">(</span>argc <span class="k3">!</span><span class="k3">=</span> <span class="n">2</span><span class="k2">)</span>
<span class="number"> 15</span>  <span class="k2">{</span>
<span class="number"> 16</span>    <a href="http://www.delorie.com/djgpp/doc/libc/libc_345.html" target="_blank">fprintf</a><span class="k2">(</span>stderr,<span class="s">"I want one string in quotes to parse for four banger math, e.g. \"5/4\"\n"</span><span class="k2">)</span><span class="k2">;</span>
<span class="number"> 17</span>    <span class="k1">return</span> <span class="n">0</span><span class="k2">;</span>
<span class="number"> 18</span>  <span class="k2">}</span>
<span class="number"> 19</span>
<span class="number"> 20</span>  <a href="http://www.delorie.com/djgpp/doc/libc/libc_293.html" target="_blank">errno</a> <span class="k3">=</span> <span class="n">0</span><span class="k2">;</span>
<span class="number"> 21</span>  parm1<span class="k3">=</span><a href="http://www.delorie.com/djgpp/doc/libc/libc_776.html" target="_blank">strtod</a><span class="k2">(</span>argv<span class="k2">[</span><span class="n">1</span><span class="k2">]</span>,<span class="k3">&amp;</span>end1<span class="k2">)</span><span class="k2">;</span>
<span class="number"> 22</span>  <span class="k1">if</span><span class="k2">(</span><a href="http://www.delorie.com/djgpp/doc/libc/libc_293.html" target="_blank">errno</a> <span class="k3">=</span><span class="k3">=</span> ERANGE<span class="k2">)</span>
<span class="number"> 23</span>  <span class="k2">{</span>
<span class="number"> 24</span>    <a href="http://www.delorie.com/djgpp/doc/libc/libc_345.html" target="_blank">fprintf</a><span class="k2">(</span>stderr,<span class="s">"First number out of range\n"</span><span class="k2">)</span><span class="k2">;</span>
<span class="number"> 25</span>    <span class="k1">return</span> <span class="n">1</span><span class="k2">;</span>
<span class="number"> 26</span>  <span class="k2">}</span>
<span class="number"> 27</span>
<span class="number"> 28</span>  <span class="k1">operator</span> <span class="k3">=</span> <span class="k2">(</span><span class="k1">char</span><span class="k2">)</span><span class="k3">*</span>end1<span class="k2">;</span>
<span class="number"> 29</span>
<span class="number"> 30</span>  end1<span class="k3">+</span><span class="k3">+</span><span class="k2">;</span>
<span class="number"> 31</span>
<span class="number"> 32</span>  parm2<span class="k3">=</span><a href="http://www.delorie.com/djgpp/doc/libc/libc_776.html" target="_blank">strtod</a><span class="k2">(</span>end1,<span class="n">0</span><span class="k2">)</span><span class="k2">;</span>
<span class="number"> 33</span>
<span class="number"> 34</span>  <span class="k1">switch</span><span class="k2">(</span><span class="k1">operator</span><span class="k2">)</span>
<span class="number"> 35</span>  <span class="k2">{</span>
<span class="number"> 36</span>    <span class="k1">case</span> <span class="s">'+'</span><span class="k2">:</span>
<span class="number"> 37</span>      result <span class="k3">=</span> parm1 <span class="k3">+</span> parm2<span class="k2">;</span>
<span class="number"> 38</span>      <span class="k1">break</span><span class="k2">;</span>
<span class="number"> 39</span>    <span class="k1">case</span> <span class="s">'-'</span><span class="k2">:</span>
<span class="number"> 40</span>      result <span class="k3">=</span> parm1 <span class="k3">-</span> parm2<span class="k2">;</span>
<span class="number"> 41</span>      <span class="k1">break</span><span class="k2">;</span>
<span class="number"> 42</span>    <span class="k1">case</span> <span class="s">'*'</span><span class="k2">:</span>
<span class="number"> 43</span>      result <span class="k3">=</span> parm1 <span class="k3">*</span> parm2<span class="k2">;</span>
<span class="number"> 44</span>      <span class="k1">break</span><span class="k2">;</span>
<span class="number"> 45</span>    <span class="k1">case</span> <span class="s">'/'</span><span class="k2">:</span>
<span class="number"> 46</span>      result <span class="k3">=</span> parm1 <span class="k3">/</span> parm2<span class="k2">;</span>
<span class="number"> 47</span>      <span class="k1">break</span><span class="k2">;</span>
<span class="number"> 48</span>    default:
<span class="number"> 49</span>      <a href="http://www.delorie.com/djgpp/doc/libc/libc_345.html" target="_blank">fprintf</a><span class="k2">(</span>stderr,<span class="s">"Operator '%c' isn't allowed\n"</span>,<span class="k1">operator</span><span class="k2">)</span><span class="k2">;</span>
<span class="number"> 50</span>      <span class="k1">return</span> <span class="n">1</span><span class="k2">;</span>
<span class="number"> 51</span>  <span class="k2">}</span>
<span class="number"> 52</span>
<span class="number"> 53</span>  intresult <span class="k3">=</span> result<span class="k2">;</span>
<span class="number"> 54</span>  <span class="k1">if</span><span class="k2">(</span>intresult <span class="k3">=</span><span class="k3">=</span> result<span class="k2">)</span>
<span class="number"> 55</span>    <a href="http://www.delorie.com/djgpp/doc/libc/libc_624.html" target="_blank">printf</a><span class="k2">(</span><span class="s">"answer is %d\n"</span>,intresult<span class="k2">)</span><span class="k2">;</span>
<span class="number"> 56</span>  <span class="k1">else</span>
<span class="number"> 57</span>    <a href="http://www.delorie.com/djgpp/doc/libc/libc_624.html" target="_blank">printf</a><span class="k2">(</span><span class="s">"answer is %lg\n"</span>,result<span class="k2">)</span><span class="k2">;</span>
<span class="number"> 58</span>
<span class="number"> 59</span>  <span class="k1">return</span> <span class="n">0</span><span class="k2">;</span>
<span class="number"> 60</span><span class="k2">}</span>
</div></div><p>

[EDIT]</p><p>Forgot the range check on second number, but you know what I mean...</p><p>[EDIT2]</p><p>The arbitrary precision lib I mentioned earlier <i>does</i> have transcendental functions, but some of them could be optimized with precalculated numbers in a file for identities, which I haven&#39;t bothered with.</p><p>I tried it just to see how fast it was on this 3.1Ghz Athlon II, but somehow argc &amp; argv were getting corrupted.  After hours of fiddling with gdb, valgrind and Electric Fence, I tried the Watcom compiler, which worked fine (although Watcom crashes on an fflush() <img src="http://www.allegro.cc/forums/smileys/tongue.gif" alt=":P" />).</p><p>Printing gives out results like:
</p><pre>
count = 7021

Input number    0.7021
Sin    0.6458224341509764981664646025062778090792175100125560862802365350598448
Cos    0.7634876446592358739582226598267228849622487768704818372243868793930424
Tan    0.8458845911504221153467969183513439373684976836083291157721866966077248

count = 7022

Input number    0.7022
Sin    0.6458987796862030057491918266634106923511167321066618731945697836968761
Cos    0.7634230585984901932657298394753035699212712280249010525166211455076285
Tan    0.846056157737701829266851733611519926546263348925174306300998247937501

count = 7023

Input number    0.7023
Sin    0.6459751187624417218523788222528204136464410918821905557397273206694932
Cos    0.7633584649035139329501939060000511971689937336425396753570132724535036
Tan    0.8462277533584315588906546332567283389122943855797825858950950746135725
</pre><p>

and here&#39;s how long it takes to print out 10000 loops with 80 bytes in the integral part and 80 bytes in the fractional part.  The first one is redirecting to results.txt, where the output above was copied from.</p><pre>pepsi@fractal_comet:/home/prog/bignums 02:49 AM $ time t &gt; results.txt

real    0m59.132s
user    0m59.021s
sys     0m0.087s
pepsi@fractal_comet:/home/prog/bignums 02:50 AM $ time t noprint

real    0m0.038s
user    0m0.038s
sys     0m0.000s
pepsi@fractal_comet:/home/prog/bignums 02:50 AM $ 
</pre><p>

The second timing result is how long it takes to calculate the trig funcs (1/30 of a second for all 30000 results) but not printing to decimal (quite a chore in itself)</p><p>[EDIT5]</p><p>I forgot to show the input number for the trig stuff...  edited all the above</p><p>[EDIT6]</p><p>Recompiling with 800 bytes of integral and decimal bytes with 700 decimal positions printed gives this for 100 loops</p><pre>
pepsi@fractal_comet:/home/prog/bignums 03:02 AM $ time t &gt; results.txt

real    4m9.194s
user    4m8.927s
sys     0m0.093s
pepsi@fractal_comet:/home/prog/bignums 03:07 AM $ time t noprint

real    0m0.004s
user    0m0.003s
sys     0m0.000s
</pre><p>

noprint is faster than before because only 100 loops</p><pre>
count = 42

Input number    0.42
Sin    0.4077604530595701859727871580863423156477998312272199837618432020183270288765336837439844031983341253779690576147116094979039277815379680051349489526859390640113444468728511707118838605394853620887365370981415293797665495368793143468270256405581832984876247762177846669463896709533912328054270139386495849713716053377167824292341132590924517670116080193774565000394404325176018879137001116501917905458262931179583116640073280342696907129516730267817169709076756630570369478068356496088806733562791025935518005717823975399647433911242565646284290408108965129580005045630325009645600351052252234931946795935673759622200090939484176528145403518844626429027118291618481207436517990068199382319726055853613
Cos    0.9130889403123082724360887896656672808656036779177695185367711006995955759007027812268532869219485750392032411157021985701743449718712839893630769060956987500869050561130530606277722475164033362715938822340958362676305487363307447311046606036732548594394880660779345469357363927362599236287787967113779712125417724313266162079002839798171344659068700365238628373106988573793108841436286988550471435158583090282785551299521559463196485941733155093326870424140702825354668014736012094116310173282063294354797176618106265223818473429154560119875265514193935088602078450686698516654784487568476528092182943197051363283336770971514484898843637969744795863457522041097293912185666895010296292417843629169566
Tan    0.4465725462845951080354340492493297863664702530228539431793643752790652121798457119308281093711337117351824302405127265043941078743201413802742986904431097907418452657673429572010439544368058258668460621337750507856743137674138128805462521543172690127434221187279537588377878373065777689804867923360071570888272946017486343012618629153112816524990960304473577139058272000642627832629543035542998512407586811092722803660439984439880202739952675782181893386116210218071303871409986764914583800844104115292506997715868582578179441467373632677384179542325076687281260631102061490708090583107700757824466976889133117431057537299832543055583282997302563566765119476476011271217072270990986942660758601073145
</pre><p>
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Arthur Kalliokoski)</author>
		<pubDate>Wed, 25 May 2011 12:13:07 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><div class="quote_container"><div class="title"><a href="http://www.allegro.cc/forums/thread/607410/918864#target">Edgar Reynaldo</a> said:</div><div class="quote"><p>but you can&#39;t represent every number with powers of 1/2.</p></div></div><p>

Nor can you represent every number with powers of 10: 10 is a totally arbitrary base.</p><p>Your posts still strongly suggest that you don&#39;t really know what you want because you don&#39;t seem to be able to grasp what is going on.</p><p>If you want your calculator to round to decimal values, then round to decimal values. Most calculators already do this:  if you enter 1/3, then multiply the answer by 3, you will get 1 again, despite the fact that 1/3 can be expressed in neither decimal nor binary. </p><p>I still don&#39;t see strong enough grounds for using a decimal base for what you are doing. In fact any hand calculator could quite easily be running on base 2 and you&#39;d never even know.</p><p>The only real grounds for a decimal base is working financial purposes. It is certainly not appropriate for your purposes, and if you intend to do any sort of numerical integration or any real number crunching for that matter, you will be slowing down your application 10-50 fold by using a decimal base.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (james_lohr)</author>
		<pubDate>Wed, 25 May 2011 13:25:19 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>Who says Edgar isn&#39;t doing a financial program? <img src="http://www.allegro.cc/forums/smileys/tongue.gif" alt=":P" />
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (weapon_S)</author>
		<pubDate>Wed, 25 May 2011 15:44:53 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><div class="quote_container"><div class="title"><a href="http://www.allegro.cc/forums/thread/607410/918864#target">Edgar Reynaldo</a> said:</div><div class="quote"><p>With my current implementation using doubles, my command line calculator / function parser is too stupid to return 51 for 5.1/0.1. That&#39;s just not acceptable to me, nor should it be acceptable to anyone using a calculator program.</p></div></div><p>
Utter nonsense.<br />When using any kind of tool, whether software or not, you have to understand its limitations. One of the limitations of computers is that floating point arithmetic has finite accuracy. There is ultimately no way around it and it&#39;s a bad idea to try to fake it in specific circumstances. It&#39;ll break down in other points.<br />Now, it may be appropriate to define operations on rational numbers (which is just a pair of integers), of which a decimal representation is just a subset. If that&#39;s what you want, then that&#39;s what you should implement (which is not difficult and is somewhat fun to do; it&#39;s not generally useful though).
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Evert)</author>
		<pubDate>Wed, 25 May 2011 17:04:19 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>I almost forgot, the 80x87 has BCD instructions.</p><p><a href="http://www.cs.umbc.edu/courses/undergraduate/313/spring04/burt_katz/lectures/Lect10/form.html">http://www.cs.umbc.edu/courses/undergraduate/313/spring04/burt_katz/lectures/Lect10/form.html</a>
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Arthur Kalliokoski)</author>
		<pubDate>Wed, 25 May 2011 17:08:27 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><div class="quote_container"><div class="title"><a href="http://www.allegro.cc/forums/thread/607410/918864#target">Edgar Reynaldo</a> said:</div><div class="quote"><p>My precision requirements are that string numbers have an exact representation when converted to data. With my current implementation using doubles, my command line calculator / function parser is too stupid to return 51 for 5.1/0.1. That&#39;s just not acceptable to me, nor should it be acceptable to anyone using a calculator program.</p></div></div><p>
As James Lohr said, you&#39;re simply not understanding what you see in calculators.  Some of them are in base 2, some are in decimal, and you generally don&#39;t notice the difference.  Different ones use different precision, but they generally display accurate integer answers to operations with divisors that don&#39;t fit in to their base evenly by the simple trick of displaying fewer digits than they calculate internally.  If you divide 1 by 3 and then multiply it by 3 it displays the result as 1.0 not because it internally calculates the result as 1.0 (most calculators don&#39;t) but because it displays fewer digits then it tracks internally.  Which is sort of like the opposite of the property you asked for - the destringification of the stringification is not equal to the original number, and that <b>loss</b> of precision is what gives them the property you like.  </p><p>Arthur Kalliokoski: I wouldn&#39;t recommend actually using the BCD opcodes.  It&#39;s comparable in efficiency to emulate that using normal integers (the BCD opcodes are slow on many x86s), and compiler support / etc is much better for non-BCD stuff.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (orz)</author>
		<pubDate>Wed, 25 May 2011 23:38:53 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><div class="quote_container"><div class="title"><a href="http://www.allegro.cc/forums/thread/607410/918896#target">orz</a> said:</div><div class="quote"><p> Arthur Kalliokoski: I wouldn&#39;t recommend actually using the BCD opcodes.  It&#39;s comparable in efficiency to emulate that using normal integers (the BCD opcodes are slow on many x86s), and compiler support / etc is much better for non-BCD stuff.</p></div></div><p>I&#39;d rather doubt this would be a problem for a calculator app.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Arthur Kalliokoski)</author>
		<pubDate>Thu, 26 May 2011 03:15:09 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><div class="quote_container"><div class="title">verthex said:</div><div class="quote"><p>
Theres LIDIA [www.cdc.informatik.tu-darmstadt.de] but I&#39;m not sure what it could do for you.
</p></div></div><p>
The <a href="http://www.cdc.informatik.tu-darmstadt.de/TI/LiDIA/#introduction">Introduction to LIDIA</a> seems to indicate that it is highly specialized in things I don&#39;t have a use for, and it makes no mention of trig / power / logarithm / other standard C/C++ functions. Thanks anyway.</p><div class="quote_container"><div class="title">Arthur Kalliokoski said:</div><div class="quote"><p>
...code example...
</p></div></div><p>
I don&#39;t see why strtod would give different results than sscanf would. As written, calling the program with 5.1/0.1 as the argument produces 51 as the answer. The problem is, I can&#39;t rely on %lg to correctly round the number in all cases. If I change it to use %.30lg I get 50.999999999999993 as the answer. What if the answer actually was 50.999999999999993 and I used %lg and got 51 as the output instead?</p><p>I just can&#39;t rely on doubles to do what I want them to do.</p><div class="quote_container"><div class="title"><a href="http://www.allegro.cc/forums/thread/607410/918867#target">Arthur Kalliokoski</a> said:</div><div class="quote"><p>
The arbitrary precision lib I mentioned earlier does have transcendental functions, but some of them could be optimized with precalculated numbers in a file for identities, which I haven&#39;t bothered with.
</p></div></div><p>
How does your library compare to <a href="http://www.tc.umn.edu/~ringx004/mapm-readme.html">MAPM</a>?</p><div class="quote_container"><div class="title"><a href="http://www.allegro.cc/forums/thread/607410/918870#target">James Lohr</a> said:</div><div class="quote"><p>
Nor can you represent every number with powers of 10: 10 is a totally arbitrary base.
</p></div></div><p>
You can represent more with powers of 10 than you can with powers of 1/2. <img src="http://www.allegro.cc/forums/smileys/tongue.gif" alt=":P" /> If doubles used positive powers of 2 and tracked the decimal point and exponent, we wouldn&#39;t be having this discussion. <img src="http://www.allegro.cc/forums/smileys/tongue.gif" alt=":P" /></p><div class="quote_container"><div class="title">James Lohr said:</div><div class="quote"><p>
Your posts still strongly suggest that you don&#39;t really know what you want because you don&#39;t seem to be able to grasp what is going on.
</p></div></div><p>
Figure it out dude, I want an exact representation (as much as possible) when converting from string to data and back. I&#39;ve said this several times. Perhaps you have poor reading comprehension, I don&#39;t know. I know what is going on, I already stated that powers of 1/2 are insufficient for my needs for data representation. Since you&#39;re so smart, why don&#39;t you enlighten me and tell me &#39;what is going on&#39;.</p><div class="quote_container"><div class="title">James Lohr said:</div><div class="quote"><p>
If you want your calculator to round to decimal values, then round to decimal values.
</p></div></div><p>
The problem is, how much precision should I choose to lose? If I decide to round everything to 10ths then I lose a lot of precision in my operations and the user may want to specify precision in the 1000ths. The MAPM library specifically allows me to choose how many significant digits their numbers should use, which makes it a lot easier for me.</p><div class="quote_container"><div class="title">James Lohr said:</div><div class="quote"><p>
I still don&#39;t see strong enough grounds for using a decimal base for what you are doing. In fact any hand calculator could quite easily be running on base 2 and you&#39;d never even know.
</p></div></div><p>
The base itself doesn&#39;t bother me, what bothers me is using negative powers of that base to represent a number, which is stupid because it usually can&#39;t be done precisely (but negative powers of base 10 are more precise than negative powers of base 2).</p><div class="quote_container"><div class="title"><a href="http://www.allegro.cc/forums/thread/607410/918874#target">weapon_S</a> said:</div><div class="quote"><p>
Who says Edgar isn&#39;t doing a financial program?
</p></div></div><p>
Well, actually I&#39;m not, but thanks for the support.</p><div class="quote_container"><div class="title"><a href="http://www.allegro.cc/forums/thread/607410/918877#target">Evert</a> said:</div><div class="quote"><p>
Utter nonsense.<br />When using any kind of tool, whether software or not, you have to understand its limitations. One of the limitations of computers is that floating point arithmetic has finite accuracy. There is ultimately no way around it and it&#39;s a bad idea to try to fake it in specific circumstances. It&#39;ll break down in other points.
</p></div></div><p>
No, what is nonsense is to return an inexact number for a mathematical operation that should have an exact value. It&#39;s the implementation of floating point arithmetic that sucks here, as you can represent any rational number with any positive base using positive powers if you track the decimal point and exponent as well. You shouldn&#39;t have to round the result of 5.1/0.1 to get the exact answer that obviously exists already. eg...
</p><pre>
5.1 e0 = 51 e-1
/         / 
0.1 e0 =  1 e-1
----------------
         51 e0
</pre><p>
When you represent the number in positive powers of any positive base greater than 1, there is no precision lost, ever (not accounting for irrational numbers here).</p><div class="quote_container"><div class="title"><a href="http://www.allegro.cc/forums/thread/607410/918896#target">orz</a> said:</div><div class="quote"><p>
Different ones use different precision, but they generally display accurate integer answers to operations with divisors that don&#39;t fit in to their base evenly by the simple trick of displaying fewer digits than they calculate internally.
</p></div></div><p>
But the problem is deciding how many digits to round the answer to. 2? 10? When you have an exact answer, you don&#39;t need to round anything.</p><div class="quote_container"><div class="title">orz said:</div><div class="quote"><p>
Which is sort of like the opposite of the property you asked for - the destringification of the stringification is not equal to the original number, and that loss of precision is what gives them the property you like.
</p></div></div><p>
I think you meant that the other way round, but I don&#39;t want 0.1 represented as 0.099999999whatever, that&#39;s just not acceptable.</p><p>In any case, I&#39;m leaning more and more towards using the MAPM library - it has a really nice C++ class called MAPM that wraps all the C code into nice operators and you can set a global precision level for all the operations. I&#39;ll have to give it a test run here over the next few days and report back. And its example calculator program knows what 5.1/0.1 is. <img src="http://www.allegro.cc/forums/smileys/wink.gif" alt=";)" />
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Edgar Reynaldo)</author>
		<pubDate>Thu, 26 May 2011 12:57:20 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><div class="quote_container"><div class="title"><a href="http://www.allegro.cc/forums/thread/607410/918972#target">Edgar Reynaldo</a> said:</div><div class="quote"><p> How does your library compare to MAPM?</p></div></div><p>I don&#39;t know, it all started when all I had was an assembler and an 8086 computer with no math chip.  I&#39;d guess that MAPM uses pure C, so I&#39;d have an advantage for smaller sizes (a few kb per &quot;number&quot;) because I can directly use the flags etc. in assembler, but most of the C implementations use FFT&#39;s to optimize multiplies etc., so they&#39;d be faster then.</p><div class="quote_container"><div class="title">Quote:</div><div class="quote"><p> 
</p></div></div><p>You can represent more with powers of 10 than you can with powers of 1/2. <img src="http://www.allegro.cc/forums/smileys/tongue.gif" alt=":P" /></p><p>So switch to base 12 then. <img src="http://www.allegro.cc/forums/smileys/cheesy.gif" alt=":D" /></p><div class="quote_container"><div class="title">Quote:</div><div class="quote"><p> I don&#39;t want 0.1 represented as 0.099999999whatever, that&#39;s just not acceptable.</p></div></div><p>Try this on your hand held calculator:<br />1 / 3 = x<br />x * 3 = x (equal to 1 &lt;-- or so it says)<br />Now subtract 1 and look at the inaccuracy it was hiding.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Arthur Kalliokoski)</author>
		<pubDate>Thu, 26 May 2011 13:04:51 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><div class="quote_container"><div class="title"><a href="http://www.allegro.cc/forums/thread/607410/918973#target">Arthur Kalliokoski</a> said:</div><div class="quote"><p>
Try this on your hand held calculator:
</p></div></div><p>
Both the Windows calculator and my CASIO fx-115ES give the answer of zero.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Edgar Reynaldo)</author>
		<pubDate>Thu, 26 May 2011 13:12:58 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><div class="quote_container"><div class="title"><a href="http://www.allegro.cc/forums/thread/607410/918974#target">Edgar Reynaldo</a> said:</div><div class="quote"><p> Both the Windows calculator and my CASIO fx-115ES give the answer of zero.</p></div></div><p>I&#39;m pretty sure all the desktop calculator applets use arbitrary precision math now, but if a CASIO hides it I&#39;m impressed!  OTOH, I haven&#39;t had a good hand held calculator for many years.  I use a cheap $1.00 calculator in the cab, I&#39;m pretty sure it&#39;d give 0.99999999 for 1/3 * 3.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Arthur Kalliokoski)</author>
		<pubDate>Thu, 26 May 2011 13:17:36 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>It&#39;s a CASIO, but it&#39;s rather complex. I just opened it up after it sitting there for a year or so. It looks like it can do simple equations, do calculations on regular and complex numbers, handle matrices and vectors and some other stuff. I used to have a really nice TI-80 something graphical calculator back in high school. That thing was great til it crapped out.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Edgar Reynaldo)</author>
		<pubDate>Thu, 26 May 2011 13:32:14 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><div class="quote_container"><div class="title"><a href="http://www.allegro.cc/forums/thread/607410/918972#target">Edgar Reynaldo</a> said:</div><div class="quote"><p>What if the answer actually was 50.999999999999993 and I used %lg and got 51 as the output instead?</p></div></div><p>
Read up on finite machine precision and the limitations that imposes. Numbers for which the difference is smaller than the machine precision are effectively the same.</p><div class="quote_container"><div class="title">Quote:</div><div class="quote"><p>You can represent more with powers of 10 than you can with powers of 1/2.</p></div></div><p>
<span class="cuss"><span>Bull<span class="cuss"><span>shit</span></span></span></span>. They&#39;re equally arbitrary.</p><div class="quote_container"><div class="title">Quote:</div><div class="quote"><p>No, what is nonsense is to return an inexact number for a mathematical operation that should have an exact value.</p></div></div><p>
The output is only as good as the input. Your input is not infinitely precisise, so neither is your output.<br />Again, understand the limitations of what you&#39;re working with.</p><div class="quote_container"><div class="title">Quote:</div><div class="quote"><p>It&#39;s the implementation of floating point arithmetic that sucks here, as you can represent any rational number with any positive base using positive powers if you track the decimal point and exponent as well. You shouldn&#39;t have to round the result of 5.1/0.1 to get the exact answer that obviously exists already.</p></div></div><p>
Neither of those numbers can be represented exactly using a finite number of powers of 2, so what the computer stores is <i>not</i> 5.1, but 5.1 +/- eps, where eps is ~1e-16 for double precision. It&#39;s not broken, you simply don&#39;t understand.<br />Now, again, you <i>could</i> implement a rational number class that allows you to store fractions exactly as a tuple of integers. That way you can work with fractions without rounding. Doesn&#39;t help you when using real numbers though.</p><div class="quote_container"><div class="title"><a href="http://www.allegro.cc/forums/thread/607410/918973#target">Arthur Kalliokoski</a> said:</div><div class="quote"><p>Try this on your hand held calculator:<br />1 / 3 = x<br />x * 3 = x (equal to 1 &lt;-- or so it says)<br />Now subtract 1 and look at the inaccuracy it was hiding.</p></div></div><p>
Cube root of 8, divide by 2 minus 1 or something like that is also a well-known example that shows finite precision on a calculator.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Evert)</author>
		<pubDate>Thu, 26 May 2011 17:49:25 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><div class="quote_container"><div class="title"><a href="http://www.allegro.cc/forums/thread/607410/918972#target">Edgar Reynaldo</a> said:</div><div class="quote"><p> (but negative powers of base 10 are more precise than negative powers of base 2)</p></div></div><p>

<b>facepalm</b>
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (james_lohr)</author>
		<pubDate>Thu, 26 May 2011 21:20:52 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><div class="quote_container"><div class="title"><a href="http://www.allegro.cc/forums/thread/607410/919001#target">Evert</a> said:</div><div class="quote"><p>
Read up on finite machine precision and the limitations that imposes. Numbers for which the difference is smaller than the machine precision are effectively the same.
</p></div></div><p>
If the difference between them was smaller than the machine precision, then you wouldn&#39;t be able to tell them apart in the first place.</p><div class="quote_container"><div class="title">Evert said:</div><div class="quote"><p>
</p><div class="quote_container"><div class="title">Edgar said:</div><div class="quote"><p>
You can represent more with powers of 10 than you can with powers of 1/2.
</p></div></div><p>
<span class="cuss"><span>Bull<span class="cuss"><span>shit</span></span></span></span>. They&#39;re equally arbitrary.
</p></div></div><p>
The proof is simple - you can represent any power of 2 with powers of 10, but you cannot represent every power of 10 with powers of 2.</p><div class="quote_container"><div class="title">Evert said:</div><div class="quote"><p>
The output is only as good as the input. Your input is not infinitely precisise, so neither is your output.<br />Again, understand the limitations of what you&#39;re working with.
</p></div></div><p>
The input is perfectly precise, so I expect the output to be perfectly precise as well as long as it is not an irrational number. I understand the limitations of floats and doubles and that is the entire purpose of this thread - to find an implementation that doesn&#39;t suffer this problem.</p><div class="quote_container"><div class="title">Evert said:</div><div class="quote"><p>
Neither of those numbers can be represented exactly using a finite number of powers of 2, so what the computer stores is not 5.1, but 5.1 +/- eps, where eps is ~1e-16 for double precision. It&#39;s not broken, you simply don&#39;t understand.
</p></div></div><p>
I know they can&#39;t be represented exactly in powers of 1/2, that&#39;s the point! So yes, it is broken as far as I&#39;m concerned, because it is perfectly reasonable to expect an exact answer when there is one! I understand that floats and doubles can&#39;t do this, so stop telling me I don&#39;t understand.</p><div class="quote_container"><div class="title">James Lohr said:</div><div class="quote"><p>
</p><div class="quote_container"><div class="title">Edgar said:</div><div class="quote"><p>
 (but negative powers of base 10 are more precise than negative powers of base 2)
</p></div></div><p>
facepalm
</p></div></div><p>
Can you represent 10e-1 in powers of 2? I don&#39;t think so. Can every power of 2 be represented in powers of 10 - yes! Can every power of 10 be represented in base 2 - no! Therefore powers of 10 can represent more numbers than powers of 2 can when using negative powers, hence base 10 is more precise when using negative powers to represent numbers.</p><p>Facepalm that, <b>sophomore</b>. <img src="http://www.allegro.cc/forums/smileys/tongue.gif" alt=":P" />
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Edgar Reynaldo)</author>
		<pubDate>Fri, 27 May 2011 03:14:55 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p><b>&lt;&lt;&lt;</b>
</p><div class="quote_container"><div class="title"><a href="http://www.allegro.cc/forums/thread/607410/919072#target">Edgar Reynaldo</a> said:</div><div class="quote"><p>
The proof is simple - you can represent any power of 2 with powers of 10, but you cannot represent every power of 10 with powers of 2.
</p></div></div><p>
I&#39;m not really sure what you mean by powers of 10 vs. powers of 2... In any case, the inaccuracy of number storage basically come down to finite storage. Infinite numbers cannot be stored in finite space and very long numbers cannot feasibly be processed either. Your basic options are floating-point numbers, which can represent a larger range of numbers with less precision, and fixed-point numbers, which can represent a smaller range of numbers with greater precision (and perhaps slower, since there are no fixed-point processing units in CPUs that I&#39;m aware of). According to Wikipedia, fixed-point data types are split into two categories: binary (base 2) and decimal (base 10). The binary ones can benefit from bitwise operations to increase performance, but suffer from worse accuracy as a result. The decimal ones would therefore be slower, but more accurate. It all depends on exactly what you&#39;re using the numbers for.</p><p><b>&gt;&gt;&gt;Prepend</b></p><p>I think what you basically want is a fixed-point data type. <img src="http://www.allegro.cc/forums/smileys/smiley.gif" alt=":)" /> Apparently GCC partially supports a draft for one in C.<span class="ref"><sup>[<a href="#">1</a>]</sup></span> Of course, I don&#39;t know if the appropriate facilities are implemented to serialize and deserialize it. If you have to convert to/from a floating-point number to serialize/deserialize then you&#39;ll lose the precision anyway. <img src="http://www.allegro.cc/forums/smileys/tongue.gif" alt=":P" /> It certainly would be nice to have fixed-point data types in all programming language standard libraries. There are some applications (financial, in particular) that can benefit a lot from the accuracy, and in those applications speed is often less important than accuracy.</p><p><b>&lt;&lt;&lt;Append</b></p><p>Personally, I find it annoying too to get incorrect results with floating-point numbers. Perhaps that is my obsessive/perfectionist nature. I never have really wrapped my head around how to handle floating-point numbers appropriately. Though since I predominantly write business applications the floating point numbers usually represent money, where accuracy usually does matter...</p><p><b>&gt;&gt;&gt;</b>
</p><div class="ref-block"><h2>References</h2><ol><li><a href="http://gcc.gnu.org/onlinedocs/gcc/Fixed_002dPoint.html">http://gcc.gnu.org/onlinedocs/gcc/Fixed_002dPoint.html</a></li></ol></div></div>]]>
		</description>
		<author>no-reply@allegro.cc (bamccaig)</author>
		<pubDate>Fri, 27 May 2011 03:33:26 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><div class="quote_container"><div class="title"><a href="http://www.allegro.cc/forums/thread/607410/919072#target">Edgar Reynaldo</a> said:</div><div class="quote"><p>The proof is simple - you can represent any power of 2 with powers of 10, but you cannot represent every power of 10 with powers of 2.</p></div></div><p>
And neither of them does a particularly good job with powers of 3 or powers of 7.<br />The reason that you can represent powers of 2 using a finite number of positions using base 10 and not the other way around is that 2 is prime and 10 is not (in fact, it&#39;s 2x5, which is why it can represent powers of 2 and powers of 5 neatly). If you pick a base with even more prime number factorisations, it could do even better (by that measure)!<br />That doesn&#39;t change the fact that both bases are equally valid choices and equally arbitrary.</p><div class="quote_container"><div class="title">Quote:</div><div class="quote"><p>The input is perfectly precise,</p></div></div><p>
No, it isn&#39;t. That&#39;s what you don&#39;t seem to get.</p><div class="quote_container"><div class="title">Quote:</div><div class="quote"><p>I understand the limitations of floats and doubles and that is the entire purpose of this thread - to find an implementation that doesn&#39;t suffer this problem.</p></div></div><p>
There isn&#39;t one, since whichever base you pick, there are rational numbers that cannot be expressed with a finite number of &quot;decimals&quot; (namely those that have a prime number in their factorisation that is not in your base).<br />Again, if you want to do operations on <i>rational numbers</i> without converting them to floats, write a class that handles rational numbers.</p><div class="quote_container"><div class="title">Quote:</div><div class="quote"><p>I know they can&#39;t be represented exactly in powers of 1/2, that&#39;s the point! So yes, it is broken as far as I&#39;m concerned, because it is perfectly reasonable to expect an exact answer when there is one! I understand that floats and doubles can&#39;t do this, so stop telling me I don&#39;t understand.</p></div></div><p>
Ok, good.<br />You don&#39;t <i>act</i> as though you understand, but if you do, good.<br />Anyway, no, the input is <i>not</i> exact. Computers operate in binary. You cannot represent &quot;5.1&quot; exactly in binary, so the input is not exact. That&#39;s leaving completely aside that, depending on where you&#39;re coming from, &quot;5.1&quot; doesn&#39;t necessarily mean &quot;51/10&quot;, but could mean &quot;a number in the range [5.05, 5.15)&quot;.<br />If you want to represent &quot;51/10&quot; exactly, write a class that handles rational numbers. <i>That</i> way you can store the number exactly and calculate things without rounding errors.<br />Floating point numbers are not broken, they may simply not be what you&#39;re looking to use. In which case, you should be more clear about what it is that you want to do.</p><div class="quote_container"><div class="title">Quote:</div><div class="quote"><p>Though since I predominantly write business applications the floating point numbers usually represent money, where accuracy usually does matter...</p></div></div><p>
If you can&#39;t tolerate numerical noise, then you should probably use a fixed-point system.<br />By the way, the &quot;issue&quot; with floating point numbers is <i>not</i> an issue with accuracy, it&#39;s an issue with precision.</p><p>EDIT: just one extra remark, but first
</p><div class="quote_container"><div class="title">Quote:</div><div class="quote"><p>Therefore powers of 10 can represent more numbers than powers of 2 can when using negative powers, hence base 10 is more precise when using negative powers to represent numbers.</p></div></div><p>
I&#39;m not going to argue the point because I can&#39;t be bothered to check it, but I suspect this may not be true. Remember, afterall, that the number of even natural numbers is <i>the same</i> as the total (odd+even) natural numbers (which is not intuitively obvious at all). I think the same sort of proof can show that your statement above is untrue, but as I said, I can&#39;t be bothered to check that.</p><p>My extra remark is this: independent of which base you choose, you will never be able to represent numbers like sqrt(2), pi or log(3) exactly by a finite number of negative powers of your base. If you do want to represent those &quot;properly&quot;, you can certainly do that, but it&#39;s a lot more complicated. Computer algebra systems (CASs) like <i>Maple</i> and <i>Mathematica</i> do that. The fact that you cannot represent them exactly as a simple number using a finite number of terms has nothing at all to do with limitations of floating point, or even integer arithmetic.<br />Again, you have to use the correct tool for the job and understand its limitations. If I want to keep sqrt(2) as sqrt(2), I&#39;ll use pen and paper (or a CAS). If I want its numerical value, I rather have it as 1.414... to whichever number of significant digits I&#39;m working with. Which representation is more &quot;correct&quot; or convenient depends on what I&#39;m going to use it for.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Evert)</author>
		<pubDate>Fri, 27 May 2011 07:00:53 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><div class="quote_container"><div class="title"><a href="http://www.allegro.cc/forums/thread/607410/919087#target">Evert</a> said:</div><div class="quote"><p>
And neither of them does a particularly good job with powers of 3 or powers of 7.
</p></div></div><p>
I can deal with that. What I can&#39;t deal with is not being able to represent powers of 10 exactly, since that is what the decimal system is based on.</p><div class="quote_container"><div class="title">Evert said:</div><div class="quote"><p>
If you pick a base with even more prime number factorisations, it could do even better (by that measure)!</p><p>That doesn&#39;t change the fact that both bases are equally valid choices and equally arbitrary.
</p></div></div><p>
You&#39;re contradicting yourself. First you say they&#39;re equally valid and then you admit that powers of 10 can represent more numbers than powers of 2. Are powers of 10 a better representation of numbers than powers of 2 or not? Well, yes they are.</p><div class="quote_container"><div class="title">Evert said:</div><div class="quote"><p>
</p><div class="quote_container"><div class="title">Edgar said:</div><div class="quote"><p>
The input is perfectly precise,
</p></div></div><p>
No, it isn&#39;t. That&#39;s what you don&#39;t seem to get.
</p></div></div><p>
What is imprecise about 5.1? It is exactly 51 10ths. The fact that a double can&#39;t represent 51 10ths is what bothers me. I get it just fine, thanks.</p><div class="quote_container"><div class="title">Evert said:</div><div class="quote"><p>
There isn&#39;t one, since whichever base you pick, there are rational numbers that cannot be expressed with a finite number of &quot;decimals&quot; (namely those that have a prime number in their factorisation that is not in your base).<br />Again, if you want to do operations on rational numbers without converting them to floats, write a class that handles rational numbers.
</p></div></div><p>
If they were represented as sums of any base greater than 1 with powers greater than or equal to 0 with a decimal point and exponent tracked separately, then any rational number could be represented exactly by them. The entire problem stems from the fact that negative powers are used to represent numbers less than one.</p><div class="quote_container"><div class="title">Evert said:</div><div class="quote"><p>
Computers operate in binary. You cannot represent &quot;5.1&quot; exactly in binary, so the input is not exact.
</p></div></div><p>
Yes you can represent it in binary if you use positive powers of two and track the decimal point and exponent.
</p><pre>
&quot;5.1&quot; = 0x33 decimal2 e-1
</pre><p>

</p><div class="quote_container"><div class="title">Evert said:</div><div class="quote"><p>
Floating point numbers are not broken, they may simply not be what you&#39;re looking to use. In which case, you should be more clear about what it is that you want to do.
</p></div></div><p>
Floating point numbers are broken if they can&#39;t represent a decimal string exactly. I&#39;ve said numerous times that I expect a string to be represented exactly in data format and to get the same string out when converting back. Why do I have to keep saying this?</p><p><b>Edit for your edit</b>
</p><div class="quote_container"><div class="title">Evert said:</div><div class="quote"><p>
I&#39;m not going to argue the point because I can&#39;t be bothered to check it, but I suspect this may not be true. Remember, afterall, that the number of even natural numbers is the same as the total (odd+even) natural numbers (which is not intuitively obvious at all). I think the same sort of proof can show that your statement above is untrue, but as I said, I can&#39;t be bothered to check that.
</p></div></div><p>
Not true. 
</p><pre>x != x + n (for n != 0)</pre><p>

</p><div class="quote_container"><div class="title">Evert said:</div><div class="quote"><p>
My extra remark is this: independent of which base you choose, you will never be able to represent numbers like sqrt(2), pi or log(3) exactly by a finite number of negative powers of your base.
</p></div></div><p>
I understand I can&#39;t exactly represent irrational numbers. I&#39;m not trying to either.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Edgar Reynaldo)</author>
		<pubDate>Fri, 27 May 2011 07:44:14 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>If it <i>is</i> for financial stuff, just use ints (counting pennies), have a special atoi routine that sticks a decimal point in the right spot, and you&#39;ll only have to use doubles for stuff like compound interest (which is never <i>exact</i> anyway).
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Arthur Kalliokoski)</author>
		<pubDate>Fri, 27 May 2011 07:47:50 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>I love nerd fights.</p><div class="quote_container"><div class="title"><a href="http://www.allegro.cc/forums/thread/607410/919088#target">Edgar Reynaldo</a> said:</div><div class="quote"><p> Floating point numbers are broken if they can&#39;t represent a decimal string exactly.
</p></div></div><p>Perhaps they are broken for your particular application, but they make good sense in terms of speed and functionality trade off.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Matthew Leverton)</author>
		<pubDate>Fri, 27 May 2011 07:58:51 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><div class="quote_container"><div class="title"><a href="http://www.allegro.cc/forums/thread/607410/919072#target">Edgar Reynaldo</a> said:</div><div class="quote"><p>
Can you represent 10e-1 in powers of 2? I don&#39;t think so. Can every power of 2 be represented in powers of 10 - yes! Can every power of 10 be represented in base 2 - no! Therefore powers of 10 can represent more numbers than powers of 2 can when using negative powers, hence base 10 is more precise when using negative powers to represent numbers.</p><p>Facepalm that, sophomore.
</p></div></div><p>


No. </p><p>Take n bits. How many unique real numbers can be represented in base 2? Easy: 2^n.  How many unique real numbers can be represented in base 10?  - <i>Always</i> fewer than 2^n, because you need at least 4 bits to represent a single digit.</p><p>So on a platform of bits (which happens to be what all ordinary computers use), base 2 has more precision. This is if you define precision to be: &quot;how accurately can an arbitrary real number be represented&quot;.</p><p>Your definition of precision appears to be &quot;how accurately can a base 10 number be represented&quot;, which makes little sense given your intended application.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (james_lohr)</author>
		<pubDate>Fri, 27 May 2011 13:10:14 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><div class="quote_container"><div class="title"><a href="http://www.allegro.cc/forums/thread/607410/919114#target">James Lohr</a> said:</div><div class="quote"><p>
Take n bits. How many unique real numbers can be represented in base 2? Easy: 2^n.  How many unique real numbers can be represented in base 10?  - Always fewer than 2^n, because you need at least 4 bits to represent a single digit.
</p></div></div><p>
If all it takes is a little extra space to get accurate results, I&#39;m fine with that.</p><div class="quote_container"><div class="title">James Lohr said:</div><div class="quote"><p>
So on a platform of bits (which happens to be what all ordinary computers use), base 2 has more precision. This is if you define precision to be: &quot;how accurately can an arbitrary real number be represented&quot;.
</p></div></div><p>
Negative powers of 2 do not have more precision than negative powers of 10, otherwise they could represent more numbers than negative powers of 10 could, which they can&#39;t. Any real number that is rational can be represented in base 10. The same can&#39;t be said for base 2 unless you use positive powers to represent the number and track the exponent.</p><div class="quote_container"><div class="title">James Lohr said:</div><div class="quote"><p>
Your definition of precision appears to be &quot;how accurately can a base 10 number be represented&quot;, which makes little sense given your intended application.
</p></div></div><p>
It makes perfect sense, given that my intended application is accurate calculation of expresssions where possible.</p><p>In any case, you&#39;ve babbled on enough about how I don&#39;t really know what I want, about how I can&#39;t grasp what is going on, blah blah blah. If you don&#39;t have any suggestions about how to achieve what I have plainly asked for numerous times, then stop posting in this thread already.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Edgar Reynaldo)</author>
		<pubDate>Fri, 27 May 2011 13:22:55 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><div class="quote_container"><div class="title"><a href="http://www.allegro.cc/forums/thread/607410/919088#target">Edgar Reynaldo</a> said:</div><div class="quote"><p>You&#39;re contradicting yourself. First you say they&#39;re equally valid and then you admit that powers of 10 can represent more numbers than powers of 2.</p></div></div><p>
That&#39;s not a contradiction.</p><div class="quote_container"><div class="title">Quote:</div><div class="quote"><p>Are powers of 10 a better representation of numbers than powers of 2 or not? Well, yes they are.</p></div></div><p>
No they&#39;re not.</p><div class="quote_container"><div class="title">Quote:</div><div class="quote"><p>Floating point numbers are broken if they can&#39;t represent a decimal string exactly.</p></div></div><p>
No they&#39;re not. They would be if they couldn&#39;t represent a <i>binary</i> string exactly, but they can. Computers use binary, not decimal.</p><div class="quote_container"><div class="title">Quote:</div><div class="quote"><p>I&#39;ve said numerous times that I expect a string to be represented exactly in data format and to get the same string out when converting back. Why do I have to keep saying this?</p></div></div><p>
Because you keep not getting that you&#39;re spouting nonsense?</p><div class="quote_container"><div class="title">Quote:</div><div class="quote"><p>Not true. <br />x != x + n (for n != 0)</p></div></div><p>
What&#39;s not true? The number of even integers being the same as the total number of integers? Shows your ignorance if that&#39;s what you meant.<br />And yes, x = x+n <i>can</i> be true if x is infinite.</p><div class="quote_container"><div class="title">Quote:</div><div class="quote"><p>I understand I can&#39;t exactly represent irrational numbers. I&#39;m not trying to either.</p></div></div><p>
No, but you&#39;re trying to do something analogous.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Evert)</author>
		<pubDate>Fri, 27 May 2011 17:09:29 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>I think that the statement that put everybody off-track was <i>move from string to double <b>and back</b></i>.<br />I&#39;m pretty sure it was not intended with infinite number of decimal places that can be obtained during a computation (ex: 1/3), but rather for the numbers that are input by humans.<br />The answer is a decimal floating-point or a decimal fixed-point number representation, as already proposed : Not because it would be more exact than a base-2 system, but because the rounding rules are on the same digits that a human would apply, and thus they appear more &#39;natural&#39;.</p><p>Everybody asked &quot;what&#39;s it for&quot; because the choice between the two (fixed or floating) depends on what kind of actual numbers you&#39;ll handle... if they are &quot;distance in meters&quot;, it still depends if you measure the distance between electrons or between galaxies (or a mix of the two).
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Audric)</author>
		<pubDate>Fri, 27 May 2011 19:03:31 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><div class="quote_container"><div class="title"><a href="http://www.allegro.cc/forums/thread/607410/919116#target">Edgar Reynaldo</a> said:</div><div class="quote"><p>
If you don&#39;t have any suggestions about how to achieve what I have plainly asked for numerous times</p></div></div><p>

We&#39;re informing you that you&#39;re trying to achieve the wrong thing. We know this because you have repeatedly demonstrated your understanding to be flawed. </p><div class="quote_container"><div class="title">Quote:</div><div class="quote"><p>Negative powers of 2 do not have more precision than negative powers of 10, otherwise they could represent more numbers than negative powers of 10 could, which they can&#39;t.</p></div></div><p>

I just explained to you that, for the same amount of memory, base 2 numbers <b>do</b> represent more real numbers than base 10 numbers. It just so happens that base 10 can (unsurprisingly) represent decimal numbers exactly - but who care? This is a minuscule subset of the set of real numbers. If you want to evaluate arbitrary mathematical expressions, then base 2 will do the job better on a computer than decimal.</p><div class="quote_container"><div class="title"><a href="http://www.allegro.cc/forums/thread/607410/919088#target">Edgar Reynaldo</a> said:</div><div class="quote"><p>If they were represented as sums of any base greater than 1 with powers greater than or equal to 0 with a decimal point and exponent tracked separately, then any rational number could be represented exactly by them. The entire problem stems from the fact that negative powers are used to represent numbers less than one.</p></div></div><p> </p><p>That&#39;s the type of naive approach to representing real numbers that students come up with in their introductory lessons to understanding floating numbers. Usually the majority of students have managed to grasp the elegance of base 2 floating point numbers within a few lectures. Of course, there are some who don&#39;t. <img src="http://www.allegro.cc/forums/smileys/tongue.gif" alt=":P" /></p><p>I think your problem is that you are so used to seeing and using decimal numbers that that is what a number is to you.  If you study mathematics or computer science at degree level, you will almost never see decimal numbers, and the few times that you do, they are crude approximations of real numbers (e.g. 3.14) used for crude calculations.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (james_lohr)</author>
		<pubDate>Sat, 28 May 2011 03:43:49 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><div class="quote_container"><div class="title"><a href="http://www.allegro.cc/forums/thread/607410/919116#target">Edgar Reynaldo</a> said:</div><div class="quote"><p>Any real number that is rational can be represented in base 10. The same can&#39;t be said for base 2 unless you use positive powers to represent the number and track the exponent.</p></div></div><p>
As has already been pointed out in this thread, there are rational real numbers that cannot be represented in base-10 with non-repeating digits (1/3rd was previously mentioned, but any simple integer fraction with a divisor that has any prime factor other than 2 or 5 also qualifies).  </p><p>Use of &quot;positive powers to represent the number and track the exponent&quot; (ie a decimal point and/or scientific notation aka floating point) is generally equally necessary or unnecessary for binary or decimal representations.  <br />It is (sort of) true that a wider variety of numbers can be represented exactly without repeating digits in decimal than binary since 10 has more prime factors than 2, but that does not mean that base 10 is more precise, and if you desired that basic property then you would be better off using base 210 than base 10 (as 210 has a wider variety of prime factors than 10 or 2).  Such base are neither more nor less precise because for any fixed amount of information the number of values that can precisely be represented is the same.  </p><p>The only significant advantage to decimal on modern computers is that it is often less complicated to interface to other decimal systems (ie input or output to/from human-readable decimal sources, standard decimal precisions/rounding rules in financial codes, etc).  There are numerous strategies for dealing with the binary-decimal interface issues, and they mostly work well.  </p><p>Your discussion of the subject repeatedly appears to show a misunderstanding of the concepts involved, though it is hard to tell for sure how much is miscommunication vs misunderstanding.  </p><p>The binary-vs-decimal issues are almost completely unrelated to fixed-vs-floating point issues, fixed-vs-variable-vs-infinite precision issues, etc.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (orz)</author>
		<pubDate>Sat, 28 May 2011 04:51:46 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>My post is too long for a.cc to process correctly, so I had to leave out some quotes relevant to my responses. Sorry about that.</p><div class="quote_container"><div class="title">Evert said:</div><div class="quote"><p>
</p><div class="quote_container"><div class="title"><a href="http://www.allegro.cc/forums/thread/607410/919072#target">Edgar</a> said:</div><div class="quote"><p>
You&#39;re contradicting yourself. First you say they&#39;re equally valid and then you admit that powers of 10 can represent more numbers than powers of 2.
</p></div></div><p>
That&#39;s not a contradiction.
</p></div></div><p>
Of course it is a contradiction. If you can represent more natural numbers with one base than you can with another, that makes the other base less valid as a choice for what you want to use. </p><div class="quote_container"><div class="title">Evert said:</div><div class="quote"><p>
</p><div class="quote_container"><div class="title">Edgar said:</div><div class="quote"><p>
Are powers of 10 a better representation of numbers than powers of 2 or not? Well, yes they are.
</p></div></div><p>
No they&#39;re not.
</p></div></div><p>
Powers of 10 can represent more numbers than powers of 2, so they are a better representation of numbers.</p><div class="quote_container"><div class="title"><a href="http://www.allegro.cc/forums/thread/607410/919132#target">Evert</a> said:</div><div class="quote"><p>
</p><div class="quote_container"><div class="title">Edgar said:</div><div class="quote"><p>
Floating point numbers are broken if they can&#39;t represent a decimal string exactly.
</p></div></div><p>
No they&#39;re not. They would be if they couldn&#39;t represent a binary string exactly, but they can. Computers use binary, not decimal.
</p></div></div><p>
Computers may use binary, but guess what - computers are intended for human use, and humans use decimal. So for mathematical purposes, they are broken.</p><div class="quote_container"><div class="title">Evert said:</div><div class="quote"><p>
</p><div class="quote_container"><div class="title">Edgar said:</div><div class="quote"><p>
I&#39;ve said numerous times that I expect a string to be represented exactly in data format and to get the same string out when converting back. Why do I have to keep saying this?
</p></div></div><p>
Because you keep not getting that you&#39;re spouting nonsense?
</p></div></div><p>
You&#39;re the one spouting nonsense. Expecting perfect string decimal to data conversion and back is a reasonable expectation for my purposes. There&#39;s no good reason that 5.1/0.1 should ever equal something other than 51. You act as if I expect the common implementation of floating point numbers to do what I want it to do. I&#39;ve said more than once I&#39;m looking for a data type that will perfectly convert to data and back to string, so it should be completely obvious by now I&#39;m not intending to use conventional floating point numbers. If you don&#39;t get that, too bad.</p><div class="quote_container"><div class="title">Evert said:</div><div class="quote"><p>
What&#39;s not true? The number of even integers being the same as the total number of integers? Shows your ignorance if that&#39;s what you meant.
</p></div></div><p>
There are always twice as many total integers as there are even integers. The fact that the count of both approaches infinity is irrelevant.</p><div class="quote_container"><div class="title">Evert said:</div><div class="quote"><p>
And yes, x = x+n can be true if x is infinite.
</p></div></div><p>
No, it can&#39;t. Subtract infinity from both sides and you have 0 == n? Since the condition was that n is non-zero, it is obvious 0 doesn&#39;t equal n. Infinity + 1 is not infinity. Infinity times 2 is not infinity. The entire number system breaks if you treat it that way, so I won&#39;t.</p><div class="quote_container"><div class="title">Evert said:</div><div class="quote"><p>
</p><div class="quote_container"><div class="title">Edgar said:</div><div class="quote"><p>
I understand I can&#39;t exactly represent irrational numbers. I&#39;m not trying to either.
</p></div></div><p>
No, but you&#39;re trying to do something analogous.
</p></div></div><p>
Representing exact decimal numbers exactly in data is not analagous to representing irrational numbers.</p><p><b>@ Audric</b><br />Here&#39;s what I originally asked for :
</p><div class="quote_container"><div class="title">Edgar said:</div><div class="quote"><p>
When scanned, &quot;#.#&quot; has to equal #.# - ie... &quot;5.1&quot; has to equal 5.1 when scanned from a string. Because currently if I use sscanf on &quot;5.1&quot; to get a double and then printf the double back out with high precision, it is 5.0999999999999996 instead of 5.1, and this occurs far too often with other numbers as well, even if it is only off by 4e-16 or so. I want to be able to move from string to double and back without losing any precision.
</p></div></div><p>
I may have misspoke in the last sentence when I said &quot;to double and back&quot;, but it should have been fairly obvious that I meant &quot;to data and back&quot;, however it would be represented. I have also clarified that several times and stated doubles aren&#39;t sufficient for my purposes, so for the last time - I want a data type that <b>can</b> move from string to data and back without any loss of precision. I haven&#39;t fully tested it yet, but it appears that the MAPM library can do this for me. So unless you have any suggestions for libraries that could do the same thing as well as or better than MAPM, further comments are likely pointless.</p><div class="quote_container"><div class="title"><a href="http://www.allegro.cc/forums/thread/607410/919137#target">Audric</a> said:</div><div class="quote"><p>
I&#39;m pretty sure it was not intended with infinite number of decimal places that can be obtained during a computation (ex: 1/3), but rather for the numbers that are input by humans.
</p></div></div><p>
Finally! Someone who actually comprehends what I&#39;ve been asking for all along.</p><p>I&#39;m not sure what the underlying representation of the MAPM data type is, but it appears to be smart enough to know that &quot;5.1&quot; means 5.1 and not 5.0999999999999996. I don&#39;t believe that any rounding has occurred during conversion to data or back to string, as default precision is 30 digits, and the only rounding done is during division or else explicitly.</p><div class="quote_container"><div class="title">Audric said:</div><div class="quote"><p>
What&#39;s it for?
</p></div></div><p>
It is for a function expression evaluation tool. You can try out the working prototype over at the </p><p><a href="http://www.allegro.cc/forums/thread/607312/918290#target">batch files, graph plotting and</a></p><p>thread started by William Labbett. If you run the expression <i>5.1/0.1</i> inside the program you can see that it fails horribly at extracting an exact answer (which clearly exists). The current implementation still uses doubles as the data type, and that is why it fails. I want to test MAPM a little more before I convert everything over to the MAPM data type.</p><p><b>@ James Lohr</b><br />Trying to achieve accurate computations is the <i>wrong thing</i>? I bow to your wisdom great sir. Which part of my understanding is flawed? The part where I understand floats and doubles can&#39;t do what I want, or the part where I asked for a data type that could, or the part where negative powers of two can&#39;t represent a decimal number exactly 100% of the time?</p><p>Did you miss the part where I said I wasn&#39;t concerned about the efficient use of memory? Who cares that base 10 can represent decimal numbers exactly? Oh well, just the people who desire accurate calculations. Never mind them though. For the last time - negative powers of base 2 will never do a better job of evaluating decimal expressions than base 10 would. That&#39;s beside the point though - see my next answer to you.</p><p>What is elegant about inaccurate calculations (from the use of base 2 with negative powers)? Nothing. You&#39;re the one who&#39;s naive if you think inaccurate calculations are acceptable where accurate calculations are both possible and desired.</p><p>Decimal numbers are what the majority of people use - not binary. The only crude approximation of a real number here stems from the fact that negative powers of two are used, and they cannot accurately reflect most decimal numbers less than one.</p><p><b>@ orz</b><br />As I said, I&#39;m not concerned with irrational numbers, or with infinite precision. What I am concerned with however is accurate calculations where they are possible.</p><p>Use of positive powers is necessary if you want to use base 2 to accurately represent rational decimal numbers.</p><p>If you can express more numbers in a certain base than another, then as far as I&#39;m concerned it is more precise. That said, base 210 is unnecessary since I&#39;m primarily concerned with accurate representation of decimal numbers.</p><p>What exactly is it that I&#39;m misunderstanding? You all seem to think I don&#39;t understand what is going on, but I&#39;ve repeatedly shown that I do, otherwise I would be satisfied with the endlessly tiresome suggestion that floats and doubles are sufficient for my needs.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Edgar Reynaldo)</author>
		<pubDate>Sat, 28 May 2011 05:39:18 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>Edgar, please some day take a course on number theory (e.g., countable sets, infinity, etc) or advanced calculus (i.e., how calculus works, not how to use it), and report back to tell me how much time you spend arguing with the teacher and the textbook and what grade you ultimately get. <img src="http://www.allegro.cc/forums/smileys/cool.gif" alt="8-)" /></p><p>Some of your dogmatic statements are as incorrect as me trying to claim that 1 + 1 = 3. Seriously, you are making a fool of yourself. Trust me, your intuition of how numbers work does not cancel out the discoveries of many smart mathematicians who devoted their lives to this sort of thing. You really should just drop that part of the discussion until you take time to educate yourself. </p><p>Because of that, I don&#39;t think you&#39;re going to get any respect regarding the actual problem at hand (representing numbers in whatever computer system you are building).
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Matthew Leverton)</author>
		<pubDate>Sat, 28 May 2011 05:58:14 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><div class="quote_container"><div class="title"><a href="http://www.allegro.cc/forums/thread/607410/919212#target">Edgar Reynaldo</a> said:</div><div class="quote"><p>
There are always twice as many total integers as there are even integers. The fact that the count of both approaches infinity is irrelevant.
</p></div></div><p>
You&#39;re disregarding basic mathematics theory here <img src="http://www.allegro.cc/forums/smileys/lipsrsealed.gif" alt=":-X" /></p><div class="quote_container"><div class="title">Quote:</div><div class="quote"><p>
No, it can&#39;t. Subtract infinity from both sides and you have 0 == n?
</p></div></div><p>
But infinity minus infinity is not 0, it&#39;s undefined <img src="http://www.allegro.cc/forums/smileys/lipsrsealed.gif" alt=":-X" /></p><div class="quote_container"><div class="title">Quote:</div><div class="quote"><p>
<i>What exactly is it that I&#39;m misunderstanding?</i> You all seem to think I don&#39;t understand what is going on, but I&#39;ve repeatedly shown that I do, otherwise I would be satisfied with the endlessly tiresome suggestion that floats and doubles are sufficient for my needs.
</p></div></div><p>
That your problem can easily be solved by just using doubles, without the need to use any of those libs. All you have to understand is how floating point numbers work, and when printing a floating point number, disregard the part that doesn&#39;t have the precission required, using rounding (IIRC, 64 bit doubles have 15 significant (decimal) digits, so if you use doubles that means if you limit your output to 15 digits you&#39;ll get an exact output (the same you&#39;d get if you used a decimal representation and print a max of 15 digits)).</p><p>In your example of 5.0999999999999996. If you only print the first 15 digits, rounding the number, you&#39;ll get 5.1 printed.</p><p>That&#39;s how calculators work (Orz explained it in his second post). This is faster (because you&#39;re using a native representation for floats), and also takes less memory (to get the same precission, you need more memory if you&#39;re using decimal representation than if you use a binary representation).
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Oscar Giner)</author>
		<pubDate>Sat, 28 May 2011 07:15:39 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><div class="quote_container"><div class="title"><a href="http://www.allegro.cc/forums/thread/607410/919217#target">Oscar Giner</a> said:</div><div class="quote"><p>
</p><div class="quote_container"><div class="title">Edgar said:</div><div class="quote"><p>
There are always twice as many total integers as there are even integers. The fact that the count of both approaches infinity is irrelevant.
</p></div></div><p>
You&#39;re disregarding basic mathematics theory here 
</p></div></div><p>
So 2*x = x where {x | !0}? Who&#39;s disregarding mathematics here?</p><div class="quote_container"><div class="title">Oscar Giner said:</div><div class="quote"><p>
But infinity minus infinity is not 0, it&#39;s undefined
</p></div></div><p>
Sorry, I prefer the real world where x - x = 0.</p><p>Treating infinity as a special number may help solve some problems in math, but I prefer to think of it as a regular number that has just gotten too large to count.</p><div class="quote_container"><div class="title">Oscar Giner said:</div><div class="quote"><p>
That your problem can easily be solved by just using doubles, without the need to use any of those libs. All you have to understand is how floating point numbers work, and when printing a floating point number, disregard the part that doesn&#39;t have the precission required, using rounding (IIRC, 64 bit doubles have 15 significant (decimal) digits, so if you use doubles that means if you limit your output to 15 digits you&#39;ll get an exact output (the same you&#39;d get if you used a decimal representation and print a max of 15 digits)).</p><p>In your example of 5.0999999999999996. If you only print the first 15 digits, rounding the number, you&#39;ll get 5.1 printed.</p><p>That&#39;s how calculators work (Orz explained it in his second post). This is faster (because you&#39;re using a native representation for floats), and also takes less memory (to get the same precission, you need more memory if you&#39;re using decimal representation than if you use a binary representation).
</p></div></div><p>
Well, I can at least say that this is the first actual explanation of how to achieve what I want without using a different data type. And it was the first comment that wasn&#39;t completely condescending and derogatory, so I thank you for that. You&#39;ve earned your cookie.</p><p>Still, I don&#39;t want to lose precision through rounding unless the user specifically asks for it, and I don&#39;t want to limit myself to 15 digits of precision either, so my choice to use MAPM still stands as valid.</p><div class="quote_container"><div class="title"><a href="http://www.allegro.cc/forums/thread/607410/919214#target">Matthew Leverton</a> said:</div><div class="quote"><p>
Edgar, please some day take a course on number theory (e.g., countable sets, infinity, etc) or advanced calculus (i.e., how calculus works, not how to use it), and report back to tell me how much time you spend arguing with the teacher and the textbook and what grade you ultimately get. <img src="http://www.allegro.cc/forums/smileys/cool.gif" alt="8-)" /></p><p>Some of your dogmatic statements are as incorrect as me trying to claim that 1 + 1 = 3. Seriously, you are making a fool of yourself. Trust me, your intuition of how numbers work does not cancel out the discoveries of many smart mathematicians who devoted their lives to this sort of thing. You really should just drop that part of the discussion until you take time to educate yourself. </p><p>Because of that, I don&#39;t think you&#39;re going to get any respect regarding the actual problem at hand (representing numbers in whatever computer system you are building).
</p></div></div><p>
You&#39;re stuck on your high horse just like James and Evert are. Too busy insulting me to give decent explanations of why I don&#39;t need to use a different data type.</p><p>You&#39;d think with all the time I spend on this forum helping other people with their problems without insulting them or talking down to them, that I would get some better responses here, but maybe that&#39;s too much to ask. <img src="http://www.allegro.cc/forums/smileys/tongue.gif" alt=":P" /></p><p>If you&#39;re all so educated and I&#39;m so ignorant, then it&#39;s rather selfish of you to sit there and mock me instead of taking the time to educate me with actual proof instead of blatant &#39;you&#39;re wrong&#39;, &#39;you can&#39;t grasp it&#39;, &#39;you are naive&#39;, &#39;you&#39;re ignorant&#39; statements, and this thread has seen more than its share of them already.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Edgar Reynaldo)</author>
		<pubDate>Sat, 28 May 2011 07:38:42 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><div class="quote_container"><div class="title"><a href="http://www.allegro.cc/forums/thread/607410/919220#target">Edgar Reynaldo</a> said:</div><div class="quote"><p> Too busy insulting me to give decent explanations of why I don&#39;t need to use a different data type.
</p></div></div><p>Showing you that there are the same amount of even integers as integers does nothing to show you why you do or don&#39;t need a different data type. You miss my point entirely.</p><p>My point is that you are mistaken about fundamental truths and refuse to take correction. You speak as if you understand more about mathematics than somebody who knows much more than you. (I&#39;m not speaking of myself.)</p><p>So you insult the mathematicians among us by pretending to know more than they, and then expect them to entertain a thoughtful and meaningful discussion about the topic at hand. </p><p>For fun here&#39;s a simple proof that there are as many even integers as integers. Give me any integer, and I will provide a unique even integer that maps to it. </p><p>Given integer n, I present you an even integer 2 * n.</p><p>If there were twice as many integers as even integers then I would run out of unique even integers to pair.</p><p>Again, back to my point. If you would argue against proven mathematics (i.e., the equivalent of saying 1 + 1 = 3), then your arguments against using floats or doubles will be perceived as the same sort of stubbornness, <i>regardless</i> if you have valid concerns.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Matthew Leverton)</author>
		<pubDate>Sat, 28 May 2011 08:43:21 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><div class="quote_container"><div class="title"><a href="http://www.allegro.cc/forums/thread/607410/919232#target">Matthew Leverton</a> said:</div><div class="quote"><p>
For fun here&#39;s a simple proof that there are as many even integers as integers. Give me any integer, and I will provide a unique even integer that maps to it. </p><p>Given integer n, I present you an even integer 2 * n.</p><p>If there were twice as many integers as even integers then I would run out of unique even integers to pair.
</p></div></div><p>
Consider the set of integers from 1 to n where n is even. Count the number of total integers from 1 to n and the number of even integers from 1 to 2. There are n total integers and n/2 even integers. Extrapolate that as far as you want to. There are always twice as many total integers as even integers for any even n and 2x + 1 / x total integers to even integers for odd n. Your &#39;proof&#39; that there are the same number of total and even integers relies on the trick of using different sets of numbers. Yes for every n there also exists 2*n, but there also exists 2*n + 1, which is odd, bringing the total ratio to 2 to one, not one to one.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Edgar Reynaldo)</author>
		<pubDate>Sat, 28 May 2011 08:57:37 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>I understand your reasoning, but your proof is one of intuition and is not mathematically valid. I cannot &quot;extrapolate as far as I want&quot; because infinity has no bounds in that context.</p><p>My proof relies on no tricks. We have two sets of numbers:</p><ul><li><p>Set A: all integers
</p></li><li><p>Set B: all even integers</p></li></ul><p>We want to know if Set A and Set B are the same size. The mathematical way to prove that is to provide a one-to-one function that maps a single element in A to a unique element in B (and B to A.)</p><p>I have provide such a function (although admittedly I have not actually proved that it is one-to-one and onto, but I don&#39;t think you are disagreeing with that). It is mathematically sound, and covers the range of everything in the two sets we are discussing. </p><p>If you wish to argue, then we aren&#39;t even speaking the same language. Mathematics has rules, and if you don&#39;t wish to follow them, then there&#39;s no common ground for discussion.</p><p>I won&#39;t try to explain it to you any further. I&#39;m not trying to be &quot;insulting,&quot; but I cannot explain an entire course on number theory in a handful of posts. (And it&#39;s not like I remember much of what I once learned anyway...)</p><p>Here&#39;s a <a href="http://en.wikipedia.org/wiki/Countable_set">small article</a> to get you started.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Matthew Leverton)</author>
		<pubDate>Sat, 28 May 2011 09:22:00 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>There are in truth three sets :<br />A - All integers<br />B - All even integers<br />C - All odd integers</p><p>Set A is by definition the union of B and C since there are only odd and even integers.</p><p>Map set A to B and set A to C :<br />Bn = 2*An<br />Cn = 2*An - 1</p><p>This gives example sets of :<br />A = {1,2,3...}<br />B = {2,4,6...}<br />C = {1,3,5...}</p><p>So for all integers in A from 1 to n there are n corresponding elements in both B and C. Since B and C are the same size, and A is the union of B and C, the actual size of A will always be 2*B. The proof that there is a 1 to 1 relationship between A and B and A and C is superseded by the definition that A is composed of the union between B and C. You can&#39;t say that A is not the union of B and C because that is the definition of &#39;all integers&#39;.</p><p>The size of A can&#39;t simultaneously equal both the size of B and the size of the union of B and C. The only remedy to this contradiction is to stick with the definition of A as the union of B and C.</p><p>In truth, it is a paradox.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Edgar Reynaldo)</author>
		<pubDate>Sat, 28 May 2011 10:02:22 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><div class="quote_container"><div class="title"><a href="http://www.allegro.cc/forums/thread/607410/919240#target">Edgar Reynaldo</a> said:</div><div class="quote"><p> the actual size of A will always be 2*B
</p></div></div><p>You are dealing with infinite set, so that is not an operation that means that A is not the same size as B.</p><p>You are saying something like:</p><ol><li><p>I have infinite sets A, B, C.
</p></li><li><p>A is proven to be the union of B and C 
</p></li><li><p>A is proven to be the same size as B
</p></li><li><p>A is proven to be the same size as C</p><br /></li><li><p>Based on my intuition of how I think infinite sets operate, I declare the mathematical proofs to be invalid.</p></li></ol><p>You cannot throw your hands up at the conclusion and say &quot;it cannot be.&quot; You must reshape your beliefs on what you have proven to be correct. Or you must show that you have incorrectly proven one of steps 1 to 4.</p><p>Your intuition that the result is a paradox because of your knowledge of how finite sets operate is not sufficient proof.</p><div class="quote_container"><div class="title">Quote:</div><div class="quote"><p> The size of A can&#39;t simultaneously equal both the size of B and the size of the union of B and C.
</p></div></div><p>That&#39;s really just circular reasoning. That&#39;s precisely the statement that we are trying to prove. It&#39;s must like saying &quot;1 + 1 does not equal 3 because 1 + 1 does not equal 3&quot;.</p><p>It <i>can</i> simultaneously be the same size if you can find a function that maps A to B and a function that maps A to B union C.</p><p>I present a simple mapping function for the latter:</p><ul><li><p>n =&gt; n</p></li></ul><p>And we already have n =&gt; 2 n for set B, so now we have proven what you said is impossible.</p><div class="quote_container"><div class="title">Quote:</div><div class="quote"><p> In truth, it is a paradox.
</p></div></div><p>You may find <a href="http://en.wikipedia.org/wiki/Hilbert%27s_paradox_of_the_Grand_Hotel">this</a> interesting. A relevant piece:<br /> 
</p><div class="quote_container"><div class="title">Quote:</div><div class="quote"><p> However, in Hilbert&#39;s aptly named Grand Hotel, the quantity of odd-numbered rooms is as many as the total quantity of rooms. In mathematical terms, the cardinality of the subset containing the odd-numbered rooms is the same as the cardinality of the set of all rooms. Indeed, infinite sets are characterized as sets that have proper subsets of the same cardinality.
</p></div></div></div>]]>
		</description>
		<author>no-reply@allegro.cc (Matthew Leverton)</author>
		<pubDate>Sat, 28 May 2011 10:57:44 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>Fine, look at it from other direction. Map all even numbers less than or equal to 2n to all integer numbers less than or equal to 2n. You can&#39;t do it.</p><p>A all integers from 1 to 2n<br />B even integers from 2 to 2n by 2</p><p>A 1 to 2n<br />B 2 + 2...2n</p><p>An = Bn/2</p><p>B {2,4,6...}<br />A {1,2,3...} OOPS {4,5,6} is missing from A</p><p>There are n numbers in B and 2*n numbers in A. Their cardinality is not the same. You have to consider the range of the set, even if you extend it to infinity.</p><p>Maybe there are special rules to deal with infinite sets, but I prefer to deal with infinite sets as if they are impossibly large finite sets. If that&#39;s not PC, oh well.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Edgar Reynaldo)</author>
		<pubDate>Sat, 28 May 2011 11:32:36 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><div class="quote_container"><div class="title"><a href="http://www.allegro.cc/forums/thread/607410/919248#target">Edgar Reynaldo</a> said:</div><div class="quote"><p> A all integers from 1 to 2n<br /> B even integers from 2 to 2n by 2
</p></div></div><p>That&#39;s not an infinite set. You are bounding it by &#39;2n&#39;, so of course A is twice as big. But if Set A is the set of all integers, and Set B is the set of all even integers, then the mapping from B to A looks like. n =&gt; n / 2.</p><div class="quote_container"><div class="title">Quote:</div><div class="quote"><p> Maybe there are special rules to deal with infinite sets, but I prefer to deal with infinite sets as if they are impossibly large finite sets. If that&#39;s not PC, oh well.
</p></div></div><p>It&#39;s not about being politically correct, it&#39;s about being <i>mathematically</i> correct.</p><p>If you want to deal with &quot;impossibly&quot; large sets, then use this notation: {1, 2, ..., N}. However, that is <i>not</i> the same as infinite sets. Any conclusion you draw from such sets does <i>not</i> apply to infinite sets, even if N is really, REALLY big!</p><p>You can not entertain a discussion that is intrinsically mathematical and then decide on using your own definitions and rules, and expect any sort of favorable outcome.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Matthew Leverton)</author>
		<pubDate>Sat, 28 May 2011 11:58:08 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><div class="quote_container"><div class="title"><a href="http://www.allegro.cc/forums/thread/607410/919212#target">Edgar Reynaldo</a> said:</div><div class="quote"><p>You all seem to think I don&#39;t understand what is going on, but I&#39;ve repeatedly shown that I do, otherwise I would be satisfied with the endlessly tiresome suggestion that floats and doubles are sufficient for my needs.</p></div></div><p>
The problem is you&#39;re repeatedly showing that you don&#39;t understand what you&#39;re talking about and/or you&#39;re speaking Martian.  Some of your comments make perfect sense, like &quot;base 210 is unnecessary since I&#39;m primarily concerned with accurate representation of decimal numbers&quot;.  Others of your statements are confusing &amp;| incoherent like &quot;As I said, I&#39;m not concerned with irrational numbers, or with infinite precision&quot; (in response to a post of mine that clearly was not talking about irrational numbers or infinite precision), or wrong like &quot;Use of positive powers is necessary if you want to use base 2 to accurately represent rational decimal numbers&quot; (depending upon how I interpret that it&#39;s either clearly false or true on a technicality but very very strongly implying things that are false), or wrong as written but maybe if I interpret a bit creatively then it could be right, like &quot;If you can represent more natural numbers with one base than you can with another, that makes the other base less valid as a choice for what you want to use&quot; (all natural numbers can be expressed exactly in all bases... maybe you meant real numbers?).  </p><p>Anyway, focusing on the purely practical end of things, you have never commented on the very simple, easy, &amp; common technique I described in my first post back on the first page (another person had already recommended the same technique, but he was confused and did not understand the nature of the technique).  If you are willing to accept a tiny loss of precision and a substantial loss of efficiency then a slight variation on that can get you even more decimal-like behavior without much extra complexity.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (orz)</author>
		<pubDate>Sat, 28 May 2011 12:17:10 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><div class="quote_container"><div class="title"><a href="http://www.allegro.cc/forums/thread/607410/919251#target">Matthew Leverton</a> said:</div><div class="quote"><p>
That&#39;s not an infinite set. You are bounding it by &#39;2n&#39;, so of course A is twice as big. But if Set A is the set of all integers, and Set B is the set of all even integers than, the mapping from B to A looks like. n =&gt; n / 2.
</p></div></div><p>
Make n infinite then. You have to keep indefinitely extending the set to make it fulfill your mapping.</p><p>{2,4,6...2n}<br />{1,2,3...n} OOPS {n + 1,n + 2...2n} Is missing! </p><p>I guess we have to go up to 4n, I mean 8n, I mean 16n, so on, so forth, forever and ever over again...</p><p>You&#39;re comparing unequal ranges of numbers. Of course you can say that for every number n there also exists a number 2n, but that doesn&#39;t prove for every set of numbers from 1 to n there also exists n numbers from 2 to n by 2.</p><p>It just doesn&#39;t cut it for me. Sorry.</p><div class="quote_container"><div class="title">Matthew Leverton said:</div><div class="quote"><p>
If you want to deal with &quot;impossibly&quot; large sets, then use this notation: {1, 2, ..., N}. However, that is not the same as infinite sets. Any conclusion you draw from such sets does not apply to infinite sets, even if N is really, REALLY big!
</p></div></div><p>
Well then if that&#39;s the way mathematicians deal with infinite sets, then I don&#39;t want any part of it, because it&#39;s just screwed up.</p><p>The cardinality of {2,4...2n} will never equal the cardinality of {1,2...2n}. It just doesn&#39;t hold up.</p><p>If you can find me a proof that 2*infinity == infinity, then maybe I&#39;ll shut up about this. Otherwise, it&#39;s probably not likely.</p><p><b>Append for orz</b><br />I posted after you did, but hadn&#39;t read it yet.</p><div class="quote_container"><div class="title"><a href="http://www.allegro.cc/forums/thread/607410/919252#target">orz</a> said:</div><div class="quote"><p>
Others of your statements are confusing &amp;| incoherent like &quot;As I said, I&#39;m not concerned with irrational numbers, or with infinite precision&quot; (in response to a post of mine that clearly was not talking about irrational numbers or infinite precision)
</p></div></div><p>
That was in response to this :
</p><div class="quote_container"><div class="title"><a href="http://www.allegro.cc/forums/thread/607410/919208#target">orz</a> said:</div><div class="quote"><p>
As has already been pointed out in this thread, there are rational real numbers that cannot be represented in base-10 with non-repeating digits (1/3rd was previously mentioned, but any simple integer fraction with a divisor that has any prime factor other than 2 or 5 also qualifies).  
</p></div></div><p>

Sorry if it was confusing or not matched to the topic. But it mostly applies, as I&#39;m not interested in precisely representing rational fractions. If I wanted that, I would be looking for a fraction library, not an arbitrary precision library.</p><div class="quote_container"><div class="title"><a href="http://www.allegro.cc/forums/thread/607410/919252#target">orz</a> said:</div><div class="quote"><p>
wrong like &quot;Use of positive powers is necessary if you want to use base 2 to accurately represent rational decimal numbers&quot; (depending upon how I interpret that it&#39;s either clearly false or true on a technicality but very strongly implying things that are false),
</p></div></div><p>
Can you represent one tenth exactly using negative powers of 2? No. That&#39;s why I said that.</p><div class="quote_container"><div class="title">orz said:</div><div class="quote"><p>
or wrong as written but maybe if I interpret a bit creatively then it could be right, like &quot;If you can represent more natural numbers with one base than you can with another, that makes the other base less valid as a choice for what you want to use&quot; (all natural numbers can be expressed exactly in all bases... maybe you meant real numbers?).  
</p></div></div><p>
I guess I meant all real numbers that don&#39;t repeat. Sorry for the confusion.</p><div class="quote_container"><div class="title">orz said:</div><div class="quote"><p>
Anyway, focusing on the purely practical end of things, you have never commented on the very simple, easy, &amp; common technique I described in my first post back on the first page (another person had already recommended the same technique, but he was confused and did not understand the nature of the technique).  If you are willing to accept a tiny loss of precision and a substantial loss of efficiency then a slight variation on that can get you even more decimal-like behavior without much extra complexity.
</p></div></div><p>

I guess you were referring to this :
</p><div class="quote_container"><div class="title"><a href="http://www.allegro.cc/forums/thread/607410/918632#target">orz</a> said:</div><div class="quote"><p>
If you only care about destringifaction+stringification not producing the original value, simply limiting every decimal stringification to 14 digits meets your requirements well over a fairly wide range of numbers, though that&#39;s actually a decrease in precision.
</p></div></div><p>
I guess I didn&#39;t actually know what that entailed, as I wasn&#39;t thinking of the number being rounded that way. Sorry if it seemed like I ignored you, I just wasn&#39;t perfectly clear on what that actually meant.</p><p>In any case, see my response to Oscar Giner, as it applies equally as a response to you :
</p><div class="quote_container"><div class="title">Edgar said:</div><div class="quote"><p>
Still, I don&#39;t want to lose precision through rounding unless the user specifically asks for it, and I don&#39;t want to limit myself to 15 digits of precision either, so my choice to use MAPM still stands as valid.
</p></div></div><p>
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Edgar Reynaldo)</author>
		<pubDate>Sat, 28 May 2011 12:18:31 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><div class="quote_container"><div class="title"><a href="http://www.allegro.cc/forums/thread/607410/919253#target">Edgar Reynaldo</a> said:</div><div class="quote"><p> I guess we have to go up to 4n, I mean 8n, I mean 16n, so on, so forth, forever and ever over again...
</p></div></div><p>Keep doing that. You&#39;ll never reach infinity.</p><div class="quote_container"><div class="title">Quote:</div><div class="quote"><p> Make n infinite then
</p></div></div><p>That makes no sense. You don&#39;t understand what infinity means in mathematical terms.</p><div class="quote_container"><div class="title">Quote:</div><div class="quote"><p> Of course you can say that for every number n there also exists a number 2n, but that doesn&#39;t prove for every set of numbers from 1 to n there also exists n numbers from 2 to n by 2.
</p></div></div><p>I don&#39;t disagree.</p><div class="quote_container"><div class="title">Quote:</div><div class="quote"><p> Well then if that&#39;s the way mathematicians deal with infinite sets, then I don&#39;t want any part of it, because it&#39;s just screwed up.
</p></div></div><p>Your lack of understanding doesn&#39;t make it &quot;screwed up.&quot; Not wanting &quot;any part of it&quot; simply makes you ignorant and a waste of time to help in these matters.</p><div class="quote_container"><div class="title">Quote:</div><div class="quote"><p> It just doesn&#39;t cut it for me. Sorry.
</p></div></div><p>Your ignorance doesn&#39;t offend me... you don&#39;t have to apologize. It&#39;s actually good to let people know that you reserve the right to reject any proven mathematical principle on the basis that it upsets your belief system. </p><p>Edit: </p><p>It goes back to my original statement: Please take some advanced (theory) mathematics courses in a higher education setting and let me know how it goes. I seriously would be interested in any recordings you could provide of you discussing your disbelief with your Ph.D. equipped math professor.  </p><p>I would love to find out if you could solve all the problems and proofs by using whatever mathematical system you have contrived. If so, then you&#39;re a much smarter person than I am. I got a bachelor&#39;s degree in math as an &quot;A student,&quot; but I cheated by using the well tested mathematical truths of old as opposed to my own inventions.</p><p>It&#39;s good to be inquisitive and to &quot;prove all things&quot; but to live in denial is, well, basically pathetic.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Matthew Leverton)</author>
		<pubDate>Sat, 28 May 2011 12:36:13 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>@orz<br />See my edit in my last post.</p><div class="quote_container"><div class="title"><a href="http://www.allegro.cc/forums/thread/607410/919254#target">Matthew Leverton</a> said:</div><div class="quote"><p>
</p><div class="quote_container"><div class="title">Edgar said:</div><div class="quote"><p>
I guess we have to go up to 4n, I mean 8n, I mean 16n, so on, so forth, forever and ever over again...
</p></div></div><p>
Keep doing that. You&#39;ll never reach infinity.
</p></div></div><p>
So the value 2n as n approaches infinity doesn&#39;t equal infinity then? Neat trick.</p><div class="quote_container"><div class="title">Matthew Leverton said:</div><div class="quote"><p>
That makes no sense. You don&#39;t understand what infinity means in mathematical terms.
</p></div></div><p>
Enlighten me then. What does infinity really mean?</p><div class="quote_container"><div class="title">Matthew Leverton said:</div><div class="quote"><p>
</p><div class="quote_container"><div class="title">Edgar said:</div><div class="quote"><p>
Of course you can say that for every number n there also exists a number 2n, but that doesn&#39;t prove for every set of numbers from 1 to n there also exists n numbers from 2 to n by 2.
</p></div></div><p>
I don&#39;t disagree.
</p></div></div><p>
Then WTF are we talking about?</p><div class="quote_container"><div class="title">Matthew Leverton said:</div><div class="quote"><p>
Your ignorance doesn&#39;t offend me... you don&#39;t have to apologize. It&#39;s actually good to let people know that you reserve the right to reject any proven mathematical principle on the basis that it upsets your belief system.
</p></div></div><p>
Ah... Back to condescension. There&#39;s the old Matthew. I wondered where you went. You were actually being quite generous in your explanations there for a while. I knew it couldn&#39;t last though.</p><p>I will freely admit that the way infinite quantities are dealt with bothers me. If that makes me an imbecile in your eyes so be it. Meh.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Edgar Reynaldo)</author>
		<pubDate>Sat, 28 May 2011 12:46:09 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><div class="quote_container"><div class="title"><a href="http://www.allegro.cc/forums/thread/607410/919255#target">Edgar Reynaldo</a> said:</div><div class="quote"><p> I will freely admit that the way infinite quantities are dealt with bothers me. If that makes me an imbecile in your eyes so be it. Meh.
</p></div></div><p>It is fine to not understand. There&#39;s plenty of things I never understood, and never will. But assuming it is nonsense because you don&#39;t understand it is where the ignorance sets in.</p><div class="quote_container"><div class="title">Quote:</div><div class="quote"><p> What does infinity really mean?
</p></div></div><p>In this context, an infinite set is one that does not have a finite number of elements. If you say something has N elements, then it is surely not infinite.</p><div class="quote_container"><div class="title">Quote:</div><div class="quote"><p> Then WTF are we talking about?
</p></div></div><p>There are the same &quot;number&quot; of even integers as odd integers as total integers. (Edit: added the quotes, since it&#39;s really the cardinality that is being discussed.)</p><p>Building an argument contrary to that by using increasingly larger finite sets is an understandable attempt, but ultimately it is irrelevant. The sets we are dealing with here are infinite.</p><p>This is a fundamental concept that you are refusing to accept. Yes, it is extremely counterintuitive. Infinity is a strange concept. Embrace it in all its glory and you&#39;ll learn why 1/3 = 0.333... and 2/3 = 0.666... and subsequently 0.333... + 0.666... = 0.999... and ultimately get to 0.999... = 1.</p><div class="quote_container"><div class="title">Quote:</div><div class="quote"><p> You were actually being quite generous in your explanations there for a while.
</p></div></div><p>There&#39;s nothing more to add when your conclusion is &quot;screw mathematics.&quot;</p><p>I&#39;m simply telling you how I perceived you to be. If I am wrong, then, well, I was bound to be at some point.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Matthew Leverton)</author>
		<pubDate>Sat, 28 May 2011 13:03:50 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><div class="quote_container"><div class="title"><a href="http://www.allegro.cc/forums/thread/607410/919258#target">Matthew Leverton</a> said:</div><div class="quote"><p>
There are the same number of even integers as odd integers as total integers.</p><p>Building an argument contrary to that by using increasingly larger finite sets is an understandable attempt, but ultimately it is irrelevant. The sets we are dealing with here are infinite.
</p></div></div><p>
The set of all even integers is a subset of the set of all integers. It can never have the same cardinality. It just doesn&#39;t make any <span class="cuss"><span>fuck</span></span>ing sense.</p><div class="quote_container"><div class="title">Matthew Leverton said:</div><div class="quote"><p>
This is a fundamental concept that you are refusing to accept. Yes, it is extremely counterintuitive. Infinity is a strange concept. Embrace it in all its glory and you&#39;ll learn why 1/3 = 0.333... and 2/3 = 0.666... and subsequently 0.333... + 0.666... = 0.999... and ultimately get to 0.999... = 1.
</p></div></div><p>
Perhaps. I&#39;ll just have to take your word for it. Just stop telling me that 2*infinity equals infinity so my brain stops hurting.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Edgar Reynaldo)</author>
		<pubDate>Sat, 28 May 2011 13:10:12 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>Gosh, what a wonderful &quot;discussion&quot;. How I love it... </p><p>It reminds of the fact that at each mathematical institute on this world, you have to deal with letters and their authors, who claim to have solved squaring the circle, or proved that sqrt(2) is not irrational, or found the ultimate world formula. It&#39;s all the same, just ignoring basic mathematical rules. Mathematicians (and philosophers) have been thinking hard about infinity for centuries, and the subject IS hard to grasp. You need the right concepts, and wrap your mind around sometimes strange thoughts. No wonder mathematicians had a hard time understanding this, and all the paradox stuff that hides inside. </p><p>Follow the two references into wikipedia, they are a good start to a long journey. If you want to understand, that is... </p><p><a href="http://en.wikipedia.org/wiki/Countable_set">http://en.wikipedia.org/wiki/Countable_set</a> <br /><a href="http://en.wikipedia.org/wiki/Hilbert%27s_paradox_of_the_Grand_Hotel">http://en.wikipedia.org/wiki/Hilbert%27s_paradox_of_the_Grand_Hotel</a>
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (tobing)</author>
		<pubDate>Sat, 28 May 2011 13:29:13 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>&quot;Infinite&quot; breaks down to &quot;in&quot; (meaning not) and &quot;finite&quot;, meaning, well, finite. (or countable).  If you could point out a number and say &quot;that&#39;s infinity&quot; all I have to do is add one to it to disprove that.</p><div class="quote_container"><div class="title"><a href="http://www.allegro.cc/forums/thread/607410/919259#target">Edgar Reynaldo</a> said:</div><div class="quote"><p> Just stop telling me that 2*infinity equals infinity so my brain stops hurting.</p></div></div><p>Look at it this way, you&#39;d have to travel an infinite distance to sail a ship off the end of the world.  Going twice as fast won&#39;t help.</p><p>BTW, that library I offered earlier uses binary, so I guess you wouldn&#39;t want it.</p><p>[EDIT]</p><p>This is the routine that decides how many decimal digits can be printed with reasonable accuracy in my bignum lib.  I limited the digits to less in the trig example above to preclude someone else coming along and saying &quot;I found an incorrect digit at the end of the 3rd result&quot; or something.</p><div class="source-code snippet"><div class="inner"><pre><span class="k1">void</span> bn_maxdecset<span class="k2">(</span><span class="k1">void</span><span class="k2">)</span>
<span class="k2">{</span>
  <span class="k1">double</span> tmp<span class="k2">;</span>
  <span class="c">//log10(256) ~= 2.4082 but practically it leaves junk at the end</span>
  bn_maxdec <span class="k3">=</span> <span class="k2">(</span><span class="k1">double</span><span class="k2">)</span> bn_fracbytes <span class="k3">*</span> <span class="n">2</span>.<span class="n">4082</span><span class="k2">;</span>
  <span class="c">//printf("\norgmaxdec = %d",bn_maxdec);</span>
  tmp <span class="k3">=</span> <span class="k2">(</span><a href="http://www.delorie.com/djgpp/doc/libc/libc_542.html" target="_blank">log</a><span class="k2">(</span>bn_fracbytes <span class="k2">)</span><span class="k2">)</span><span class="k2">;</span>
  tmp <span class="k3">*</span><span class="k3">=</span> <span class="n">1</span>.<span class="n">5</span><span class="k2">;</span>
  tmp <span class="k3">=</span> <a href="http://www.delorie.com/djgpp/doc/libc/libc_330.html" target="_blank">floor</a><span class="k2">(</span>tmp<span class="k2">)</span><span class="k2">;</span>
  bn_maxdec <span class="k3">=</span> <span class="k2">(</span><span class="k1">double</span><span class="k2">)</span> bn_maxdec <span class="k3">-</span> tmp<span class="k2">;</span>
  <span class="c">//printf("\nnew maxdec = %d\n",bn_maxdec);</span>
  <span class="c">//fflush(stdout);</span>
<span class="k2">}</span>
</pre></div></div><p>
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Arthur Kalliokoski)</author>
		<pubDate>Sat, 28 May 2011 13:32:14 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>There are three different concepts involved here, and intermixed in mathematically invalid ways: cardinality, ordinal numbers, and approximation by an infinite series (which is what a good part of calculus is about). </p><p>When you talk about infinity and countable sets, stick to cardinality. Which is well explained in that wikipedia article about countable sets. In terms of cardinality, it is indeed true that 2*NN=NN, where NN denotes the cardinality of the natural numbers, here commonly referred to as infinity. <img src="http://www.allegro.cc/forums/smileys/wink.gif" alt=";)" /> </p><p>When you talk about 0.9999....=1, that is actually a statement about approximation, and is in fact stating that the series of numbers 0.9, 0.99, 0.999, 0.9999, ... etc. ad inf. ultimately converges to 1, in terms of the limes (or limit) in sense of calculus.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (tobing)</author>
		<pubDate>Sat, 28 May 2011 13:44:08 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><div class="quote_container"><div class="title"><a href="http://en.wikipedia.org/wiki/Hilbert&#39;s_paradox_of_the_Grand_Hotel">Hilbert&#39;s paradox of the Grand Hotel</a> said:</div><div class="quote"><p>
In mathematical terms, the cardinality of the subset containing the odd-numbered rooms is the same as the cardinality of the set of all rooms.
</p></div></div><p>
This is what I can&#39;t grasp.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Edgar Reynaldo)</author>
		<pubDate>Sat, 28 May 2011 13:52:12 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>Consider this:  A line a centimeter long has an infinite number of points in it.  If you doubt this, specify two points that are &quot;infinitely close together&quot; and I&#39;ll just get the average distance from one end.</p><p>On the other hand, a square centimeter in area has an infinity of lines at 90 degrees to one edge, is this &quot;more&quot; infinity or not?  We can move up to a cube that measures 1cm^3 if you like.</p><p>Or going back to the square centimeter:  Not only does it have an infinity of straight lines parallel to each edge, but it also has an infinity of lines at arbitrary angles.  As well as an infinite amount of parabolic arcs.  Extend <i>this</i> to the cube.  And yet the centimeter line segment has &quot;just as many&quot; points as these other things in a cube.  Or at least you can never run out.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Arthur Kalliokoski)</author>
		<pubDate>Sat, 28 May 2011 13:59:09 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>Oops. Be careful here: If you talk about a line of 1cm, you talk about real numbers, not natural numbers. But, real numbers do have a different cardinality than natural numbers, which amounts to a mathematical proof (originally given by Cantor) that there are indeed more real numbers than natural numbers. So the real numbers do have a different, and greater, cardinality than natural numbers! </p><p>In contrast, the rational numbers have the same cardinality as the natural numbers. For a proof (which is giving an bijective map between the two sets) again see Cantor. </p><p>Want some more? </p><p>It was for a long time unknown if there is any cardinality between the natural numbers and the real numbers. This is known as Cantor&#39;s continuum problem. The answer is quite unexpected, and again goes very deep into mathematical logic: You can have both answers... in terms of commonly accepted axioms Cantor&#39;s continuum hypothesis is not decidable. That is, you can neither prove it nor disprove. This goes back to the work of Kurt Gödel during the 1930s or so.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (tobing)</author>
		<pubDate>Sat, 28 May 2011 14:07:21 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>Another point I forget to mention: There is a proof that states that it is possible to represent <i>any</i> real number exactly with an infinite sum of increasing negative powers (binary or decimal).  Therefore if memory and computation is not part of the equation, then it is possible to represent your decimal values <i>exactly</i> using infinite floating point numbers.  This is of course hypothetical, since no computer has an infinite amount of memory, but it&#39;s no less hypothetical than your grounds for using decimal over binary.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (james_lohr)</author>
		<pubDate>Sat, 28 May 2011 14:38:21 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>The infinite sum is, to be a tiny little bit more precise, a notion for an (infinite) series of numbers that converges to the desired real number. Which is again approximation, where you can approximate the real number to any given degree of exactness by the numbers of that series. Which again means that 1) you don&#39;t get the exact value, and 2) you need more members of the series to achieve a better approximation...
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (tobing)</author>
		<pubDate>Sat, 28 May 2011 15:00:46 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><div class="quote_container"><div class="title"><a href="http://www.allegro.cc/forums/thread/607410/919268#target">Edgar Reynaldo</a> said:</div><div class="quote"><p>
This is what I can&#39;t grasp.
</p></div></div><p>

Isn&#39;t is simple ?</p><p>You&#39;ve got an infinite number of rooms. Which means no matter how many you use, there&#39;ll also be more of them spare.</p><p>You just consider the odd numbered ones : you&#39;ve still got the same situation. You won&#39;t run out of empty rooms no matter how people want to stay in them.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (William Labbett)</author>
		<pubDate>Sat, 28 May 2011 15:10:02 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>This also bothers me (infinite guests in an infinite roomed hotel leaving <img src="http://www.allegro.cc/forums/smileys/huh.gif" alt="???" /> empty rooms?) :<br /><img class="math" src="http://www.allegro.cc/images/tex/b/e/bea65aa4352d1c87b2ebf51ba6c7498b-120.png" alt="&lt;math&gt;\infty - \infty \not\equiv 0&lt;/math&gt;" /></p><p>@James Lohr<br />I think this<br /><a href="http://www.doc.ic.ac.uk/teaching/distinguished-projects/2009/m.herrmann.pdf">Coinductive definitions and real numbers</a><br />might be what you were looking for. In any case it is moot since we don&#39;t have infinite resources to compute with.</p><p>Even given that information, it is still far simpler to represent one tenth in decimal than binary. <img src="http://www.allegro.cc/forums/smileys/tongue.gif" alt=":P" />
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Edgar Reynaldo)</author>
		<pubDate>Sat, 28 May 2011 15:29:21 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><div class="quote_container"><div class="title"><a href="http://www.allegro.cc/forums/thread/607410/919268#target">Edgar Reynaldo</a> said:</div><div class="quote"><p>
This is what I can&#39;t grasp.
</p></div></div><p>
It&#39;s quite simple. In layman&#39;s terms: If you want to count all the even-numbered rooms, you&#39;ll never finish. If you want to count all the rooms, you&#39;ll also never finish. That&#39;s what cardinality is about (in simplified terms).</p><p>Using the 2n proof: If you want to show that any whole number n exists for which 2*n does not exist, then you will have to walk the list of whole numbers and check each one, until you reach one that you cannot multiply by 2. If you do this, you will never stop walking the list, because it does not end.</p><p>Infinity is not a number, not even an incredibly large one. It&#39;s a concept. And because of this, the rules that apply to numbers do not apply to infinity. You cannot subtract anything from infinity, in fact, you cannot perform any arithmetic on it at all. It&#39;s not a number. <br />Mathematicians use the concept of infinity and the infinity symbol to indicate a series that does not end, or a number that grows without bounds (&quot;approaches infinity&quot; means just that).</p><p>Back to your original problem. Computers use binary numbers to do their calculations, which means they can, by nature, only deal with whole numbers (and a limited range of them at that). However, most things in life don&#39;t map nicely to whole numbers, so people invented a bunch of strategies to overcome this problem:
</p><ul><li><p>Big integers. This strategy uses an array of integers, each representing a part of the number; the array grows as needed, so there is no theoretical maximum to the size of the number you can represent this way. You&#39;re still bound to whole numbers only, and the amount of available and addressable RAM is of course still a constraint.
</p></li><li><p>Fractions. Store each number as a pair of integers (or better yet, bigints), one for the numerator and one for the denominator. This way, you can represent all rational numbers (again, within the physical constraints of the hardware), but there are quite some limitations - the representation isn&#39;t automatically canonical (e.g. doing 2/3 * 3/2 naively will yield 6/6, which you want to reduce to 1/1 for all sorts of reasons), and canonicalizing your numbers can be quite costly. Also, finding good approximations for irrational numbers is really really complex matter.
</p></li><li><p>Fixed-point. Store your number as an integer, but adjust your calculations so that it is understood to mean multiples of a step &lt; 1. For example, 1/0x10000 used to be popular (giving you a binary fixed-point format with 16 bits for the whole-number part and 16 for the fractional part); for financial calculations, you rather want to use 1/100 or 1/10000, so that your integer represents cents or 1/100ths of cents. The advantage of this is that it&#39;s very fast (you do your calculations on native integers), and your precision is exactly the same over the entire range, in absolute terms - that is, adding 0.1 to a number always produces the same rounding error no matter what you add it to.
</p></li><li><p>Floating-point. Store your number as a pair of integers, one for the mantissa and one for the exponent. This pair (m,e) is then understood to mean m * 2<sup>e</sup>, where both m and e may be negative. (Technically, it&#39;s implemented a tad bit different, but the general idea is the same). What this means is first of all, that the precision is roughly the same over the entire range, in <i>relative</i> terms. That is, if a certain number has a 0.01% rounding error when represented as a float, then ten thousand times that number will also have a 0.01% rounding error, approximately.</p></li></ul><p>And now comes the problem. While each of these can represent a particular subset of the set of real numbers, none of them can represent them all. One can at least represent all rational numbers, the rest of them can&#39;t even do that. All but the fraction approach have one numeric base for which they can offer exact representations, while all other rational numbers can only be approximated.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Tobias Dammers)</author>
		<pubDate>Sat, 28 May 2011 16:01:31 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><div class="quote_container"><div class="title"><a href="http://www.allegro.cc/forums/thread/607410/919280#target">Edgar Reynaldo</a> said:</div><div class="quote"><p>
This also bothers me (infinite guests in an infinite roomed hotel leaving <img src="http://www.allegro.cc/forums/smileys/huh.gif" alt="???" /> empty rooms?) :
</p></div></div><p>

No, an infinite number of guest would match an inifinite number of rooms 1 for 1.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (William Labbett)</author>
		<pubDate>Sat, 28 May 2011 17:33:56 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><div class="quote_container"><div class="title"><a href="http://www.allegro.cc/forums/thread/607410/919253#target">Edgar Reynaldo</a> said:</div><div class="quote"><p>
{2,4,6...2n}<br />{1,2,3...n} OOPS {n + 1,n + 2...2n} Is missing!
</p></div></div><p>
But those are finite sets. An infinite set doesn&#39;t have a last element (or it can have a last element, but then it cannot have a first element (for countable sets, which those both are)). So for those sets to be infinite, elements n+1, n+2... do actually exist.</p><p>So what you actually have is:<br />{2, 4, 6... 2n...}<br />{1, 2, 3... n...}</p><div class="quote_container"><div class="title">Quote:</div><div class="quote"><p>
The cardinality of {2,4...2n} will never equal the cardinality of {1,2...2n}
</p></div></div><p>
Of course the cardinality of {2,4...2n} is less than the cardinality of {1,2...2n}. But you did the same mistake: those are finite sets, not infinite.</p><p>And no, saying that n = infinite is not valid, because that would make you claim that an infinite set has a last element (thus not being infinite... so... are you saying that infinite sets are not infinite?).</p><p>The error you&#39;re doing again and again is extrapolating rules that apply to finite sets to infinite sets. You&#39;re trying to &quot;prove&quot; your believes on infinite sets by proving those believes are actually true for finite sets.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Oscar Giner)</author>
		<pubDate>Sat, 28 May 2011 20:01:06 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>Think about it this way. We all know in a finite set of integers from 1 to 2n there are 2n integers and n even integers. Why does this suddenly stop being true when you can no longer count n? It&#39;s just not right.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Edgar Reynaldo)</author>
		<pubDate>Sun, 29 May 2011 02:55:10 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><div class="quote_container"><div class="title"><a href="http://www.allegro.cc/forums/thread/607410/919321#target">Edgar Reynaldo</a> said:</div><div class="quote"><p>Why does this suddenly stop being true when you can no longer count n?</p></div></div><p>
It does. You can easily show that it does. There&#39;s no more to it than that.<br />Consider the set N of all integers. Now construct a new set, E, such that E = {2n, for all n in N}. How many elements are there in the set E (what is the cardinality of E)? Well, the same as there are in N, by construction. However, also by construction, E contains all even integers. Conclusion: there are as many even integers as there are integers.<br />Similarly, construct the set O such that O = {2n+1, n in N} and lets say that 0 is in N. By construction, O has the same number of elements (same cardinality) as N. They&#39;re also all odd integers. Conclusion: there are as many odd integers as there are integers.<br />Suppose there are more integers than even integers. Then there must be an n in N for which 2n is not in E. But 2n is an even integer if n is an integer, and must be in E. Therefore there is no n in N for which 2n is not in E, and the number of elements in N is not larger than the number of elements in E.</p><div class="quote_container"><div class="title">Quote:</div><div class="quote"><p>It&#39;s just not right.</p></div></div><p>
It&#39;s 100% right. It&#39;s just counterintuitive (or rather, you don&#39;t have the right kind of intuition). If you want to raise an objection, find a fault in the logic of the proof. &quot;I don&#39;t understand how this works&quot; is not a valid objection.<br />So if you want to continue the debate, I suggest you try to find an error in the proof. Actually, I don&#39;t really suggest that you waste your time trying to do that. You&#39;re better off dropping this here.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Evert)</author>
		<pubDate>Sun, 29 May 2011 03:15:24 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>What&#39;s the limit of (2n/n) as n approaches infinity? Two. You&#39;d have me believe it suddenly stops being 2 and becomes 1. That&#39;s hogwash.</p><p>Like I said before, you&#39;re comparing unequal ranges :<br />A {2,4,6...}<br />B {1,2,3...} OOPS We didn&#39;t bother to include 4,5,6. Guess we have to extend the range of A to {...8,10,12} OOPS we forgot to include 7-12 in B. Repeat ad nauseam...</p><p>The idea that there are twice as many integers as even integers cannot simultaneously be both true and false.</p><p>Don&#39;t try to convince me further. Arbitrarily breaking rules that apply to countable numbers just so uncountable numbers will work is crap.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Edgar Reynaldo)</author>
		<pubDate>Sun, 29 May 2011 04:19:48 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>Closing thread to save somebody from wasting time with a response.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Matthew Leverton)</author>
		<pubDate>Sun, 29 May 2011 04:35:42 +0000</pubDate>
	</item>
</rss>
