On Tue, Jan 18, 2011 at 09:42:08PM +0000, Tony Duell wrote:
I wish there
was a widely available, widely known general purpose
programming language which had a "number with precision" type, which
would Do The Right Thing when doing things like multiplying values
together - ie, decreasing the precision - and would let you specify a
required minimum precision for results or function parameters, with
exceptions being thrown if those can't be achieved. It would be nice to
be able to automate away the problem of "measure with a micrometer, mark
with chalk, cut with an axe".
Some years ago, at the HPCC conference (I think
it was in 2007), Hugh
Steers presents a piece of software he'd written where you could specift
the precieon you wanted in the answer and which would then use better
approximations as necesssty until that precision had been reached.
Thanks, but I'm more concerned with sensible use value approximate
values as opposed to how to *get* approximate values.
To take a somewhat contrived example, let's suppose that I have a
variable $sqrt_two whose value is 1.414, known to be correct to 4
significant figures.
I can square it, and get $two == 1.999396, which is slightly less
precise. I can raise $sqrt_two to the fourth power and get $four ==
3.997584364816 which is slightly less precise again. Continue abusing
the approximation enough, raising 1.414 to the ninth and seventeenth
powers and you end up with 255.382etc and 65220.etc. So we've gone from
a fairly good approximation to a bloody awful one.
I would like to be able to:
* mark a variable as being an approximation, and with how precise it is;
* for those markers to propagate to any result that arises from a
calculation involving that variable;
those two are somewhat similar to "tainting" of variables in perl; I
presume that similar features exist in other dynamic languages and maybe
in some others.
* for those propagated markers to have the appropriate precision
attached. NB this is *not* just a copy of the original precision -
while 1.414 is sqrt(2) to 4sf, 65220 is a lot less precise!
* to specify required precisions for the variables I store my results
in, or for functions' return values, or for functions' parameters, and
to throw exceptions if those are violated
--
David Cantrell | Official London Perl Mongers Bad Influence
If you have received this email in error, please add some nutmeg
and egg whites, whisk, and place in a warm oven for 40 minutes.