|
| 08 Feb 2017 12:24 PM |
local nan1=0/0 local nan2=50/0 print(nan1,nan2) print(nan1==nan2) print(nan1==nan1) print(nan1==0/0) print(nan1~=nan2) |
|
|
| Report Abuse |
|
|
|
| 08 Feb 2017 12:27 PM |
| also why is 50/0 registering as inf instead of nan even though it is still division by 0 |
|
|
| Report Abuse |
|
|
|
| 08 Feb 2017 12:33 PM |
bump didnt see anything too interesting in the c setups |
|
|
| Report Abuse |
|
|
AxonMega
|
  |
| Joined: 29 Aug 2014 |
| Total Posts: 2403 |
|
|
| 08 Feb 2017 01:08 PM |
| They made it like that so you can check if a number is not real. |
|
|
| Report Abuse |
|
|
|
| 08 Feb 2017 01:11 PM |
It might answer your question if you set nan1 = 1/0 in the above script
|
|
|
| Report Abuse |
|
|
TimeTicks
|
  |
| Joined: 27 Apr 2011 |
| Total Posts: 27115 |
|
|
| 08 Feb 2017 01:29 PM |
because -1.#IND ~= 1.#INF
and -1.#IND ~= 0/0
|
|
|
| Report Abuse |
|
|
|
| 08 Feb 2017 03:10 PM |
no but nan1==nan1 returns FALSE...
|
|
|
| Report Abuse |
|
|
|
| 08 Feb 2017 03:36 PM |
like i cannot see the logic why nan is not nan
print(0/0==0/0)
it is very very strange...
also here is something extremely ironic
print(type(0/0))
nan stands for Not a Number yet type says it is a number xDDDD |
|
|
| Report Abuse |
|
|
TimeTicks
|
  |
| Joined: 27 Apr 2011 |
| Total Posts: 27115 |
|
|
| 08 Feb 2017 03:39 PM |
it doesnt matter
stackoverflow . com /questions/19107302/in-lua-what-is-inf-and-ind
|
|
|
| Report Abuse |
|
|
|
| 08 Feb 2017 03:40 PM |
i dont care about 10/0 not being 0/0 i want to know why 0/0 is not 0/0
|
|
|
| Report Abuse |
|
|
| |
|
|
| 08 Feb 2017 04:04 PM |
dividing by 0 is undefined
something undefined cannot be equal to anything as it does not exist in the first place. |
|
|
| Report Abuse |
|
|
|
| 08 Feb 2017 04:16 PM |
| "also why is 50/0 registering as inf instead of nan even though it is still division by 0" If you take Calculus you'll learn that dividing by 0 is practically infinite in most cases. The only reason we don't define the result of dividing a non-zero number by zero as infinite is because it's not true 100% of the time. "something undefined cannot be equal to anything as it does not exist in the first place." would be the semantic answer. For Lua to be able to tell that 0/0 == 0/0, it'd have to know what 0/0 was before it became -inf, and it doesn't store this information. This is the same for non-zero divisions by zero as well, meaning 5/0 ## #### ## math.huge. The reason 0/0 ~= -1/0 even though they don't print out the same value is probably because of an edge case in Lua (if dividend == 0 and divisor == 0 then) where 0/0 returns a different type of undefined value that always returns false in comparisons. |
|
|
| Report Abuse |
|
|
|
| 08 Feb 2017 10:33 PM |
| but doesnt nil represent a non existent value but nil==nil is true |
|
|
| Report Abuse |
|
|
|
| 08 Feb 2017 10:35 PM |
| and i still find it funny that type(nan) is a number |
|
|
| Report Abuse |
|
|
cntkillme
|
  |
| Joined: 07 Apr 2008 |
| Total Posts: 44956 |
|
|
| 08 Feb 2017 10:38 PM |
No the reason nans are not equal to each other is because they're designed to be that way.
Technically there are 2^53 - 1 different NaNs (the representation) but that's not the reason. The reasons from what I assume are that dealing with NaNs can cause problems if you don't get value out of it.
i.e. x < nan will always yield false because nan cannot be greater than or less than any other number (or nan). The reason nan ~= nan was probably so it was easy to determine if a number was nan. |
|
|
| Report Abuse |
|
|
cntkillme
|
  |
| Joined: 07 Apr 2008 |
| Total Posts: 44956 |
|
|
| 08 Feb 2017 10:39 PM |
"if you don't get value out of it." meant to say if you don't get nan out of it (it being comparing it or doing arithmetic blah blah) |
|
|
| Report Abuse |
|
|
|
| 08 Feb 2017 10:41 PM |
but to know if a number is nan you would have to compare it to being under or above numbers or to it having a denominator of 0
and lua thinks Not a Number is a number which i assume is just for simplicity |
|
|
| Report Abuse |
|
|
cntkillme
|
  |
| Joined: 07 Apr 2008 |
| Total Posts: 44956 |
|
|
| 08 Feb 2017 10:42 PM |
"and lua thinks Not a Number is a number which i assume is just for simplicity" It's not Lua that thinks that. It's because NaN's type _is_ a number. It's represented just how every other number is represented, except that the exponent = 2^expbits-1 and mantissa ~= 0 |
|
|
| Report Abuse |
|
|
|
| 08 Feb 2017 10:45 PM |
| is there a way to know if the result of division is undefined for numbers other than 0 because it returns infinity so i think you could only find out if you know the denominator because you could have inf/1 |
|
|
| Report Abuse |
|
|
|
| 08 Feb 2017 10:46 PM |
| i think i should just make my own undefined value that can be returned from using a division function |
|
|
| Report Abuse |
|
|
booing
|
  |
| Joined: 04 May 2009 |
| Total Posts: 6594 |
|
|
| 08 Feb 2017 10:55 PM |
1 #include [stdio.h] 2 3 int main() { 4 float a = 1.0 / 0.0; 5 float b = 2.0 / 0.0; 6 7 printf("%f : %08x / %f : %08x\n", a, b); 8 return 0; 9 }
inf : 610cbb48 / inf : 610cbb58
|
|
|
| Report Abuse |
|
|
booing
|
  |
| Joined: 04 May 2009 |
| Total Posts: 6594 |
|
| |
|
|
| 08 Feb 2017 10:57 PM |
at least using the console in chrome
that is simply not true.
I tested with the values 30/0 and 50/0
essentially I compared 30/0 == 50/0 and received true. but what I also got is that 30/0 == infinity
|
|
|
| Report Abuse |
|
|
|
| 08 Feb 2017 10:58 PM |
| no you are incorrect, nan is a result of 0/0 apparently, not any larger or smaller numbers |
|
|
| Report Abuse |
|
|