Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I find it hard (but not impossible) to believe that any other check on <code>args[i]</code> would be faster than <code>double.IsNan()</code>.</p> <p>One possibility is if this is a function. There is an overhead with calling functions, sometimes substantial, especially if the function itself is relatively small.</p> <p>You could take advantage of the fact that the bit patterns for IEEE754 NaNs are well known and just do some bit checks (<em>without</em> calling a function to do it) - this would remove that overhead. In C, I'd try that with a macro. Where the exponent bits are all 1 and the mantissa bits are not all 0, that's a NaN (signalling or quiet is decided by the sign bit but you're probably not concerned with that). In addition, NaNs are never equal to one another so you could test for equality between <code>args[i]</code> and itself - false means it's a NaN.</p> <p>Another possibility may be workable if the array is used more often than it's changed. Maintain another array of booleans which indicate whether or not the associated double is a NaN. Then, whenever one of the doubles changes, compute the associated boolean.</p> <p>Then your function becomes:</p> <pre><code>public void DoSomething(double[] args, boolean[] nan) { for(int i = 0; i &lt; args.Length; i++) { if (nan[i]) { //Do something } } } </code></pre> <p>This is the same sort of "trick" used in databases where you pre-compute values only when the data changes rather than every time you read it out. If you're in a situation where the data is being used a lot more than being changed, it's a good optimisation to look into (most algorithms can trade off space for time).</p> <p>But remember the optimisation mantra: <em>Measure, don't guess!</em></p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload