Rocksolid Light

Welcome to novaBBS (click a section below)

mail  files  register  newsreader  groups  login

Message-ID:  

War isn't a good life, but it's life. -- Kirk, "A Private Little War", stardate 4211.8


tech / sci.electronics.design / Re: 0.0 / 0.0 = -NAN ?

SubjectAuthor
o Re: 0.0 / 0.0 = -NAN ?Carlos E.R.

1
Re: 0.0 / 0.0 = -NAN ?

<cci8ki-h54.ln1@Telcontar.valinor>

  copy mid

https://www.novabbs.com/tech/article-flat.php?id=96147&group=sci.electronics.design#96147

  copy link   Newsgroups: sci.electronics.design
Path: i2pn2.org!i2pn.org!weretis.net!feeder8.news.weretis.net!news.szaf.org!fu-berlin.de!uni-berlin.de!individual.net!not-for-mail
From: robin_li...@es.invalid (Carlos E.R.)
Newsgroups: sci.electronics.design
Subject: Re: 0.0 / 0.0 = -NAN ?
Date: Tue, 3 May 2022 23:11:08 +0200
Lines: 36
Message-ID: <cci8ki-h54.ln1@Telcontar.valinor>
References: <85f22bc1-17c7-46d9-b933-4c6238863740n@googlegroups.com>
Mime-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 8bit
X-Trace: individual.net Bb9NUw2MvGtIVg5b8AoF1Ask+ien3jnWd5f9KaW0tDyUOx4B0R
X-Orig-Path: Telcontar.valinor!not-for-mail
Cancel-Lock: sha1:QNEI37fyXDF6iiKGNqCL2q4UczQ=
User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:91.0) Gecko/20100101
Thunderbird/91.8.0
Content-Language: en-CA
In-Reply-To: <85f22bc1-17c7-46d9-b933-4c6238863740n@googlegroups.com>
 by: Carlos E.R. - Tue, 3 May 2022 21:11 UTC

On 2022-04-30 17:31, Skybuck Flying wrote:
> When exception masks are all enabled to stop the processor from throwing floating point exceptions the following calculation produces a somewhat strange result:
>
> 0.0 / 0.0 = -nan
>
> (At least in Delphi).
>
> For now I will assume this is the case in C/C++ as well and with that I mean on x86/x64 which should and seems to be following IEEE 754 floating-point format.
>
> I am a little bit surprised by this and I want/need to know more. Where is this defined that 0.0 / 0.0 should be -NAN ?!?
>
> Problem is with the code, example:
>
> T := 0;
> D := 0.0 / 0.0;
> P := T * D;
>
> This screws up P. instead of P being zero, P is now also -NAN ?!?

I have not read the entire thread, so maybe someone has already said it;
but yes, NAN is correct in math, because 0/0 is "undefined" (think
limits). It can be zero, one, any number, even infinite. So multiplying
T·D can actually be 0·∞, which is again "undefined", so NAN.

>
> I find this very strange but ok.
>
> I guess a simple solution could be to set D to 0 explicitly for this case, is there perhaps another solution ? Maybe some kind of mask or rounding mode so that additional branch is not necessary ???
>
> Bye for now,
> Skybuck.

--
Cheers, Carlos.


tech / sci.electronics.design / Re: 0.0 / 0.0 = -NAN ?

1
server_pubkey.txt

rocksolid light 0.9.81
clearnet tor