Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #91231

Re: a more precise distance algorithm

From Christian Gollwitzer <auriocus@gmx.de>
Newsgroups comp.lang.python
Subject Re: a more precise distance algorithm
Date 2015-05-26 07:33 +0200
Organization A noiseless patient Spider
Message-ID <mk10hj$oa8$1@dont-email.me> (permalink)
References <b2e66a94-7a89-4be9-bbf7-9434396cc178@googlegroups.com> <5563e453$0$12990$c3e8da3$5496439d@news.astraweb.com>

Show all headers | View raw


Am 26.05.15 um 05:11 schrieb Steven D'Aprano:
> mismatch after 3 trials
> naive: 767.3916150255787
> alternate: 767.3916150255789
> hypot: 767.3916150255787
>
>
> which shows that:
>
> (1) It's not hard to find mismatches;
> (2) It's not obvious which of the three methods is more accurate.


The main problem is not necessarily precision. A square root is a very 
precise operation in floating point math, the relative precision 
*increases* by sqrt. The big problem is overflow. Take e.g. a=3*10^160, 
b=4*10^160, then the exact result is c=5*10^160. But:

 >>> a=3e160
 >>> b=4e160
 >>> math.sqrt(a**2+b**2)
Traceback (most recent call last):
   File "<stdin>", line 1, in <module>
OverflowError: (34, 'Result too large')
 >>> math.hypot(a,b)
5e+160


	Christian

Back to comp.lang.python | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

a more precise distance algorithm ravas <ravas@outlook.com> - 2015-05-25 12:21 -0700
  Re: a more precise distance algorithm felix <felix@epepm.cupet.cu> - 2015-05-25 16:06 -0400
  Re: a more precise distance algorithm Christian Gollwitzer <auriocus@gmx.de> - 2015-05-25 22:27 +0200
    Re: a more precise distance algorithm ravas <ravas@outlook.com> - 2015-05-25 14:03 -0700
  Re: a more precise distance algorithm Gary Herron <gary.herron@islandtraining.com> - 2015-05-25 13:20 -0700
    Re: a more precise distance algorithm ravas <ravas@outlook.com> - 2015-05-25 14:05 -0700
  Re: a more precise distance algorithm Steven D'Aprano <steve@pearwood.info> - 2015-05-26 13:11 +1000
    Re: a more precise distance algorithm ravas <ravas@outlook.com> - 2015-05-25 21:13 -0700
      Re: a more precise distance algorithm Gary Herron <gherron@digipen.edu> - 2015-05-25 22:09 -0700
        Re: a more precise distance algorithm ravas <ravas@outlook.com> - 2015-05-25 22:49 -0700
    Re: a more precise distance algorithm Christian Gollwitzer <auriocus@gmx.de> - 2015-05-26 07:33 +0200
    Re: a more precise distance algorithm Brian Blais <bblais@gmail.com> - 2015-05-27 14:00 -0400
    Re: a more precise distance algorithm Oscar Benjamin <oscar.j.benjamin@gmail.com> - 2015-05-27 23:03 +0100
    Re: a more precise distance algorithm Dennis Lee Bieber <wlfraed@ix.netcom.com> - 2015-05-27 23:04 -0400
  Re: a more precise distance algorithm Ian Kelly <ian.g.kelly@gmail.com> - 2015-05-25 22:42 -0600
    Re: a more precise distance algorithm ravas <ravas@outlook.com> - 2015-05-25 21:59 -0700
  Re: a more precise distance algorithm random832@fastmail.us - 2015-05-26 09:40 -0400
  Re: a more precise distance algorithm random832@fastmail.us - 2015-05-26 09:51 -0400
  Re: a more precise distance algorithm Robin Becker <robin@reportlab.com> - 2015-05-27 14:02 +0100

csiph-web