## digitalmars.D - Disable NaN and Inf

• Jonathan Crapuchettes (6/6) Feb 05 2010 I would like to divide one array by another using the slice syntax so th...
• Andrei Alexandrescu (5/14) Feb 06 2010 I don't know of a way. You may want to try first running a loop
• =?ISO-8859-1?Q?Pelle_M=E5nsson?= (4/18) Feb 06 2010 I would not recommend this unless you use the denominator array to
• dsimcha (8/22) Feb 06 2010 At this point it's probably useless to vectorize, though. You may as we...
• Andrei Alexandrescu (3/27) Feb 06 2010 I don't know. In such cases only experimentation can prove anything.
• Don (8/39) Feb 06 2010 I think it would depend heavily on cache effects. If it fits into the L1...
• Jonathan Crapuchettes (3/17) Feb 06 2010 Are NaNs and Infs the result of a CPU operation or is that part of the D...
• Trass3r (1/3) Feb 06 2010 http://en.wikipedia.org/wiki/NaN
• BCS (5/7) Feb 06 2010 The Floating point unit does all of that and IIRC it's defined as part o...
Jonathan Crapuchettes <jcrapuchettes gmail.com> writes:
```I would like to divide one array by another using the slice syntax so that I
can
benefit from the vectorized operation, but I am running into a problem. Some of
the numbers is my denominator array are 0, producing NaNs and Infs in the
result.

My question is: Is there a way to force 0/0 and x/0 to result in 0?

Thank you,
JC
```
Feb 05 2010
Andrei Alexandrescu <SeeWebsiteForEmail erdani.org> writes:
```Jonathan Crapuchettes wrote:
I would like to divide one array by another using the slice syntax so
that I can benefit from the vectorized operation, but I am running into
a problem. Some of the numbers is my denominator array are 0, producing
NaNs and Infs in the result.

My question is: Is there a way to force 0/0 and x/0 to result in 0?

Thank you,
JC

I don't know of a way. You may want to try first running a loop
replacing 0 with inf throughout the denominator array. Then run
vectorized division; any non-inf divided by inf yields 0.

Andrei
```
Feb 06 2010
=?ISO-8859-1?Q?Pelle_M=E5nsson?= <pelle.mansson gmail.com> writes:
```On 02/06/2010 09:16 AM, Andrei Alexandrescu wrote:
Jonathan Crapuchettes wrote:
I would like to divide one array by another using the slice syntax so
that I can benefit from the vectorized operation, but I am running
into a problem. Some of the numbers is my denominator array are 0,
producing NaNs and Infs in the result.

My question is: Is there a way to force 0/0 and x/0 to result in 0?

Thank you,
JC

I don't know of a way. You may want to try first running a loop
replacing 0 with inf throughout the denominator array. Then run
vectorized division; any non-inf divided by inf yields 0.

Andrei

I would not recommend this unless you use the denominator array to
divide several other arrays.

A single pass will be faster and more clear, I think.
```
Feb 06 2010
dsimcha <dsimcha yahoo.com> writes:
```== Quote from Andrei Alexandrescu (SeeWebsiteForEmail erdani.org)'s article
Jonathan Crapuchettes wrote:
I would like to divide one array by another using the slice syntax so
that I can benefit from the vectorized operation, but I am running into
a problem. Some of the numbers is my denominator array are 0, producing
NaNs and Infs in the result.

My question is: Is there a way to force 0/0 and x/0 to result in 0?

Thank you,
JC

I don't know of a way. You may want to try first running a loop
replacing 0 with inf throughout the denominator array. Then run
vectorized division; any non-inf divided by inf yields 0.
Andrei

At this point it's probably useless to vectorize, though.  You may as well just
write something like:

if(isNaN(arr2[i])) {
result[i] = 0;
} else {
result[i] = arr1[i] / arr2[i];
}
```
Feb 06 2010
Andrei Alexandrescu <SeeWebsiteForEmail erdani.org> writes:
```dsimcha wrote:
== Quote from Andrei Alexandrescu (SeeWebsiteForEmail erdani.org)'s article
Jonathan Crapuchettes wrote:
I would like to divide one array by another using the slice syntax so
that I can benefit from the vectorized operation, but I am running into
a problem. Some of the numbers is my denominator array are 0, producing
NaNs and Infs in the result.

My question is: Is there a way to force 0/0 and x/0 to result in 0?

Thank you,
JC

I don't know of a way. You may want to try first running a loop
replacing 0 with inf throughout the denominator array. Then run
vectorized division; any non-inf divided by inf yields 0.
Andrei

At this point it's probably useless to vectorize, though.  You may as well just
write something like:

if(isNaN(arr2[i])) {
result[i] = 0;
} else {
result[i] = arr1[i] / arr2[i];
}

I don't know. In such cases only experimentation can prove anything.

Andrei
```
Feb 06 2010
Don <nospam nospam.com> writes:
```Andrei Alexandrescu wrote:
dsimcha wrote:
== Quote from Andrei Alexandrescu (SeeWebsiteForEmail erdani.org)'s
article
Jonathan Crapuchettes wrote:
I would like to divide one array by another using the slice syntax so
that I can benefit from the vectorized operation, but I am running into
a problem. Some of the numbers is my denominator array are 0, producing
NaNs and Infs in the result.

My question is: Is there a way to force 0/0 and x/0 to result in 0?

Thank you,
JC

I don't know of a way. You may want to try first running a loop
replacing 0 with inf throughout the denominator array. Then run
vectorized division; any non-inf divided by inf yields 0.
Andrei

At this point it's probably useless to vectorize, though.  You may as
well just
write something like:

if(isNaN(arr2[i])) {
result[i] = 0;
} else {
result[i] = arr1[i] / arr2[i];
}

I don't know. In such cases only experimentation can prove anything.

Andrei

I think it would depend heavily on cache effects. If it fits into the L1
cache, my guess is that doing a vectorized check followed by a
vectorized division would be faster. But it's extremely difficult to
predict this kind of thing.
If the array is larger than the cache, the per-element check would
definitely be much quicker, since you'd only have one cache miss instead
of two.
```
Feb 06 2010
Jonathan Crapuchettes <jcrapuchettes gmail.com> writes:
```Are NaNs and Infs the result of a CPU operation or is that part of the D
language?
JC

Andrei Alexandrescu wrote:
Jonathan Crapuchettes wrote:
I would like to divide one array by another using the slice syntax so
that I can benefit from the vectorized operation, but I am running
into a problem. Some of the numbers is my denominator array are 0,
producing NaNs and Infs in the result.

My question is: Is there a way to force 0/0 and x/0 to result in 0?

Thank you,
JC

I don't know of a way. You may want to try first running a loop
replacing 0 with inf throughout the denominator array. Then run
vectorized division; any non-inf divided by inf yields 0.

Andrei

```
Feb 06 2010
Trass3r <un known.com> writes:
``` Are NaNs and Infs the result of a CPU operation or is that part of the D
language?

http://en.wikipedia.org/wiki/NaN
```
Feb 06 2010
BCS <none anon.com> writes:
```Hello Jonathan,

Are NaNs and Infs the result of a CPU operation or is that part of the
D language?

The Floating point unit does all of that and IIRC it's defined as part of
the IEEE standard.

--
<IXOYE><
```
Feb 06 2010