Long primitive NaN value required

Scenario:

1) I have a long state variable that may or may not be set.

2) This long variable has valid values โ€‹โ€‹from Long.MIN_VALUE to Long.MAX_VALUE, including zero

3) This is performance sensitive code, so I don't want to use a long shell type

How do I write down the โ€œinstalledโ€ type of verification for a long time? Should I add a second boolean to check if long is valid or not? It seems messy. I know that I could use a long shell here, but it seems like a performance waste creating so many objects and checking for zero.

Pseudocode (this is what I want):

class foo {

long someLong = NaN; //NaN = hypothetical not a number like Double

public reset() {
  someLong = NaN;
}

public doSomethingElse() {
   if(someLong !=NaN) {
     //report
     reset();
   }
}

public doSomeStuff() {
  if(someLong == NaN) {
   someLong = //something
  }
}

}

}
+3
source share
4

NaN. , .

, Long - ?

, , , , ?

+3

, , null NaN.

+2

NaN . , ( Long), .

+1

Long.MIN_VALUE, ,

Long.MIN_VALUE == -Long.MIN_VALUE

.

The problem with using it, it can make the code more complicated. For this reason I use double, instead, integer values โ€‹โ€‹less than +/- 2 ^ 53 can be represented without errors.

+1
source

All Articles