|
|
|
![]() |
|
|||||||
|
||||||||
![]() |
|
|
Thread Tools | Rate Thread | Display Modes |
|
|
|
#1
|
||||
|
||||
|
Ok so I'm trying to get Autonomous up and running and forgot what I would use to convert from Int to Boolean,
if you can even do that. I'm not even sure anymore. ![]() |
|
#2
|
|||||
|
|||||
|
Re: Autonomous Problems / I'm dumb
While there are casts, the best (most readable and consistent across languages) way to convert a number to Boolean is to us a comparison operator. For example, if you want false when x is zero and true otherwise, use (x!=0).
Edit: that's ok with integers. With floats, you have to watch out for NaN cases. My favorite way to test around all of the cases where x is not a number is to do something like (x==x && x!=0). Last edited by GeeTwo : 28-03-2016 at 19:53. |
|
#3
|
||||
|
||||
|
Re: Autonomous Problems / I'm dumb
Ok so I'm not crazy (well no more so than usual). Thank you!
![]() |
|
#4
|
||||
|
||||
|
Re: Autonomous Problems / I'm dumb
Quote:
These exist for a reason! Code:
Double.isNaN(double) Double.isInfinite(double) |
|
#5
|
|||||
|
|||||
|
Re: Autonomous Problems / I'm dumb
Calling two negatively phrased language-dependent methods is better than one comparison? If there were an isFinite() method, I would consider using it.
|
|
#6
|
||||
|
||||
|
Re: Autonomous Problems / I'm dumb
Better than using x==x, which seems hacky and is surely platform/implementation dependent. It's better not to introduce hard-to-diagnose bugs in your code.
|
![]() |
| Thread Tools | |
| Display Modes | Rate This Thread |
|
|