Go to Post It's over, done, let's move on and be positive. Next year maybe everything will be perfect. :cool: - Ed Sparks [more]
Home
Go Back   Chief Delphi > Technical > Programming > Java
CD-Media   CD-Spy  
portal register members calendar search Today's Posts Mark Forums Read FAQ rules

 
Reply
 
Thread Tools Rate Thread Display Modes
  #1   Spotlight this post!  
Unread 28-03-2016, 19:41
HatterTingamaji's Avatar
HatterTingamaji HatterTingamaji is offline
Registered User
AKA: Liberty Forrest-Okey
FRC #4277 (Thingamajjigers)
Team Role: Programmer
 
Join Date: Feb 2016
Rookie Year: 2015
Location: Minnesota
Posts: 5
HatterTingamaji is an unknown quantity at this point
Question Autonomous Problems / I'm dumb

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.
Reply With Quote
  #2   Spotlight this post!  
Unread 28-03-2016, 19:50
GeeTwo's Avatar
GeeTwo GeeTwo is online now
Technical Director
AKA: Gus Michel II
FRC #3946 (Tiger Robotics)
Team Role: Mentor
 
Join Date: Jan 2014
Rookie Year: 2013
Location: Slidell, LA
Posts: 3,511
GeeTwo has a reputation beyond reputeGeeTwo has a reputation beyond reputeGeeTwo has a reputation beyond reputeGeeTwo has a reputation beyond reputeGeeTwo has a reputation beyond reputeGeeTwo has a reputation beyond reputeGeeTwo has a reputation beyond reputeGeeTwo has a reputation beyond reputeGeeTwo has a reputation beyond reputeGeeTwo has a reputation beyond reputeGeeTwo has a reputation beyond repute
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).
__________________

If you can't find time to do it right, how are you going to find time to do it over?
If you don't pass it on, it never happened.
Robots are great, but inspiration is the reason we're here.
Friends don't let friends use master links.

Last edited by GeeTwo : 28-03-2016 at 19:53.
Reply With Quote
  #3   Spotlight this post!  
Unread 28-03-2016, 19:55
HatterTingamaji's Avatar
HatterTingamaji HatterTingamaji is offline
Registered User
AKA: Liberty Forrest-Okey
FRC #4277 (Thingamajjigers)
Team Role: Programmer
 
Join Date: Feb 2016
Rookie Year: 2015
Location: Minnesota
Posts: 5
HatterTingamaji is an unknown quantity at this point
Re: Autonomous Problems / I'm dumb

Ok so I'm not crazy (well no more so than usual). Thank you!
Reply With Quote
  #4   Spotlight this post!  
Unread 28-03-2016, 22:05
euhlmann's Avatar
euhlmann euhlmann is offline
CTO, Programmer
AKA: Erik Uhlmann
FRC #2877 (LigerBots)
Team Role: Leadership
 
Join Date: Dec 2015
Rookie Year: 2015
Location: United States
Posts: 298
euhlmann has much to be proud ofeuhlmann has much to be proud ofeuhlmann has much to be proud ofeuhlmann has much to be proud ofeuhlmann has much to be proud ofeuhlmann has much to be proud ofeuhlmann has much to be proud ofeuhlmann has much to be proud of
Re: Autonomous Problems / I'm dumb

Quote:
Originally Posted by GeeTwo View Post
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).


These exist for a reason!
Code:
Double.isNaN(double)
Double.isInfinite(double)
Reply With Quote
  #5   Spotlight this post!  
Unread 29-03-2016, 06:35
GeeTwo's Avatar
GeeTwo GeeTwo is online now
Technical Director
AKA: Gus Michel II
FRC #3946 (Tiger Robotics)
Team Role: Mentor
 
Join Date: Jan 2014
Rookie Year: 2013
Location: Slidell, LA
Posts: 3,511
GeeTwo has a reputation beyond reputeGeeTwo has a reputation beyond reputeGeeTwo has a reputation beyond reputeGeeTwo has a reputation beyond reputeGeeTwo has a reputation beyond reputeGeeTwo has a reputation beyond reputeGeeTwo has a reputation beyond reputeGeeTwo has a reputation beyond reputeGeeTwo has a reputation beyond reputeGeeTwo has a reputation beyond reputeGeeTwo has a reputation beyond repute
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.
__________________

If you can't find time to do it right, how are you going to find time to do it over?
If you don't pass it on, it never happened.
Robots are great, but inspiration is the reason we're here.
Friends don't let friends use master links.
Reply With Quote
  #6   Spotlight this post!  
Unread 29-03-2016, 09:31
euhlmann's Avatar
euhlmann euhlmann is offline
CTO, Programmer
AKA: Erik Uhlmann
FRC #2877 (LigerBots)
Team Role: Leadership
 
Join Date: Dec 2015
Rookie Year: 2015
Location: United States
Posts: 298
euhlmann has much to be proud ofeuhlmann has much to be proud ofeuhlmann has much to be proud ofeuhlmann has much to be proud ofeuhlmann has much to be proud ofeuhlmann has much to be proud ofeuhlmann has much to be proud ofeuhlmann has much to be proud of
Re: Autonomous Problems / I'm dumb

Quote:
Originally Posted by GeeTwo View Post
Calling two negatively phrased language-dependent methods is better than one comparison? If there were an isFinite() method, I would consider using it.
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.
Reply With Quote
Reply


Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump


All times are GMT -5. The time now is 08:09.

The Chief Delphi Forums are sponsored by Innovation First International, Inc.


Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.
Copyright © Chief Delphi