View unanswered posts | View active topics It is currently Wed Oct 01, 2014 12:18 pm






Reply to topic  [ 6 posts ] 
Modulo Assignment 
Author Message
Professor
User avatar

Joined: Sat May 18, 2013 1:24 pm
Posts: 272
Location: Olympia, WA
Post Modulo Assignment
I've whittled down my error to this:
Code:
task main() {
   float current_encoder = 0;
   current_encoder %= 360;
}

The compiler tells me "**Severe*:Illegal compiler use of 'float constant' in second parm". It still compiles and downloads, however. :?

_________________
FTC Team 6424, the 'Oly Cow - Chief programmer.
FRC Team 4450, Olympia Robotics Federation (ORF).

and also quadrotors. Quadrotors!


Sat Aug 10, 2013 11:27 am
Profile
Professor
User avatar

Joined: Sat May 18, 2013 1:24 pm
Posts: 272
Location: Olympia, WA
Post Re: Modulo Assignment
Ok. If you cast the result before you assign the value, it will work.
Code:
task main() {
   float current_encoder = 0;
   current_encoder = (float)(current_encoder%360);
}

_________________
FTC Team 6424, the 'Oly Cow - Chief programmer.
FRC Team 4450, Olympia Robotics Federation (ORF).

and also quadrotors. Quadrotors!


Sat Aug 10, 2013 11:51 am
Profile
Moderator
Moderator
User avatar

Joined: Wed Mar 05, 2008 8:14 am
Posts: 3223
Location: Rotterdam, The Netherlands
Post Re: Modulo Assignment
Well, taking the modulo of a floating point number is kind of pointless (no pun intended), it's only for bytes, ints and longs.

= Xander

_________________
| Professional Conduit of Reasonableness
| (Title bestowed upon on the 8th day of November, 2013)
| My Blog: I'd Rather Be Building Robots
| ROBOTC 3rd Party Driver Suite: [Project Page]


Sat Aug 10, 2013 3:33 pm
Profile WWW
Professor
User avatar

Joined: Sat May 18, 2013 1:24 pm
Posts: 272
Location: Olympia, WA
Post Re: Modulo Assignment
It works, just happens to truncate the decimal as well. I was using a float because I was doing other things with the variable, and didn't want to cast it. So, I guess I was being lazy again :P

_________________
FTC Team 6424, the 'Oly Cow - Chief programmer.
FRC Team 4450, Olympia Robotics Federation (ORF).

and also quadrotors. Quadrotors!


Sat Aug 10, 2013 8:03 pm
Profile
Moderator
Moderator
User avatar

Joined: Wed Mar 05, 2008 8:14 am
Posts: 3223
Location: Rotterdam, The Netherlands
Post Re: Modulo Assignment
This makes more sense:
Code:
task main() {
   float current_encoder = 0;
   current_encoder = round(current_encoder)%360;
}

Alternatively:
Code:
task main() {
   float current_encoder = 0;
   current_encoder = (int)current_encoder%360;
}

= Xander

_________________
| Professional Conduit of Reasonableness
| (Title bestowed upon on the 8th day of November, 2013)
| My Blog: I'd Rather Be Building Robots
| ROBOTC 3rd Party Driver Suite: [Project Page]


Sun Aug 11, 2013 12:56 am
Profile WWW
Professor
User avatar

Joined: Sat May 18, 2013 1:24 pm
Posts: 272
Location: Olympia, WA
Post Re: Modulo Assignment
Ah. Thank you.

_________________
FTC Team 6424, the 'Oly Cow - Chief programmer.
FRC Team 4450, Olympia Robotics Federation (ORF).

and also quadrotors. Quadrotors!


Sun Aug 11, 2013 1:06 am
Profile
Display posts from previous:  Sort by  
Reply to topic   [ 6 posts ] 

Who is online

Users browsing this forum: jpalnick and 2 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  



Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group.
Designed by ST Software for PTF.