Re: [PLUG] Unexpected math result

2011-12-21 Thread Keith Lofstrom
On Wed, Dec 21, 2011 at 12:24:09PM -0800, Michael R wrote: > main() { > ??? int x; > ??? x > = ( .00425 * 2 ) + .0025; > ??? > printf ( "%24.24f\n", x - ( .00425 * 2) - .0025); > > } > > mikeraz@hive:~> gcc fp.c -o fp > mikeraz@hive:~> ./fp > -0.011001096345 Shouldn't that be som

Re: [PLUG] Unexpected math result

2011-12-21 Thread Aaron Burt
On Wed, Dec 21, 2011 at 12:24:09PM -0800, Michael R wrote: > I was reminded of something this morning.?? Perhaps you will enjoy > the puzzle. > > ?mikeraz@hive:~> perl -e 'my $x = (.0425 * 2) + .0025; > print $x - (.0425 * 2) - .0025, $/;' > ?2.16840434497101e-18 In preparation for January's me

Re: [PLUG] Unexpected math result

2011-12-21 Thread Russell Senior
> "Tim" == Tim writes: >> What languages use that, or something giving non-floating point >> results these days? Tim> I haven't had to use such things for a long time, but Scheme has Tim> a data type for floating point and another data type for exact Tim> numbers. [...] Yeah, and Common Li

Re: [PLUG] Unexpected math result

2011-12-21 Thread Michael R
Tim wrote: > On Wed, Dec 21, 2011 at 12:24:09PM -0800, Michael R wrote: >> >> >> I was reminded of something this morning.?? Perhaps you will enjoy >> the puzzle. > > That's floating point for you, and most traditional languages use that > by default. If you want exact calculations, you have to

Re: [PLUG] Unexpected math result

2011-12-21 Thread Rich Shepard
On Wed, 21 Dec 2011, Richard C. Steffens wrote: > Back in the late '70s and early '80s I wrote programs for small businesses > with a version of Turbo Pascal that used binary coded decimal for math. > What languages use that, or something giving non-floating point results > these days? Dick,

Re: [PLUG] Unexpected math result

2011-12-21 Thread Richard C. Steffens
On 12/21/2011 01:33 PM, Tim wrote: >> What languages use that, or something giving non-floating >> point results these days? > I haven't had to use such things for a long time, but Scheme has a > data type for floating point and another data type for exact numbers. > Python's documentation has a go

Re: [PLUG] Unexpected math result

2011-12-21 Thread Tim
> What languages use that, or something giving non-floating > point results these days? I haven't had to use such things for a long time, but Scheme has a data type for floating point and another data type for exact numbers. Python's documentation has a good explanation of the issue and makes th

Re: [PLUG] Unexpected math result

2011-12-21 Thread Richard C. Steffens
On 12/21/2011 12:29 PM, Tim wrote: > That's floating point for you, and most traditional languages use that > by default. If you want exact calculations, you have to use a library > specifically designed for them, or use a language which does exact > calculations by default. Back in the late '70

Re: [PLUG] Unexpected math result

2011-12-21 Thread Tim
On Wed, Dec 21, 2011 at 12:24:09PM -0800, Michael R wrote: > > > I was reminded of something this morning.?? Perhaps you will enjoy > the puzzle. > > ?mikeraz@hive:~> perl -e 'my $x = > (.0425 * > 2) + .0025; print $x - (.0425 * 2) - .0025, $/;' > > ?2.16840434497101e-18 > ?mikeraz@hive:~> >