Path: csiph.com!eternal-september.org!feeder.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail From: Eric Sosman Newsgroups: comp.lang.java.programmer Subject: Re: double == double Date: Sat, 15 Oct 2016 14:15:58 -0400 Organization: A noiseless patient Spider Lines: 27 Message-ID: References: <8737k0qd38.fsf@golem.phantasia.org> <87zim5es30.fsf@golem.phantasia.org> Mime-Version: 1.0 Content-Type: text/plain; charset=windows-1252; format=flowed Content-Transfer-Encoding: 7bit Injection-Date: Sat, 15 Oct 2016 18:15:42 -0000 (UTC) Injection-Info: mx02.eternal-september.org; posting-host="414bcd8b93082233ddd2be90cf792575"; logging-data="25060"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX19eUGRZewNsYqE5aNA1xT8X" User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64; rv:45.0) Gecko/20100101 Thunderbird/45.4.0 In-Reply-To: Cancel-Lock: sha1:hYnE8Fh04SuWQ3n5uqQK3+vhfsE= Xref: csiph.com comp.lang.java.programmer:35770 On 10/15/2016 12:36 PM, 4ndre4 wrote: > [...] I was > developing a 3D geometry library in C++ a while ago. The problem I had > was testing the library. I had to test for equality with 0.0 when > checking whether a point belonged to a plane or a rect was the result of > the intersection between two planes. Determining the delta to use turned > out to be extremely difficult, if not impossible. I ended up tranforming > my classes into templates with a generic type for the coordinate, and > write tests using integers instead of doubles. I'd be curious to know if > there can be a better solution. Although it covers only the two-dimensional case, this paper http://www.cpsc.ucalgary.ca/~marina/papers/Segment_intersection.ps describes some techniques you might find (or might have found) useful. In particular, it offers a method of determining *exactly* whether a sum of floating-point values would be negative, zero, or positive if it were carried out in perfect precision. -- esosman@comcast-dot-net.invalid "Everybody must get stoned." Looks like the Swedish Academy was.