Sign in to follow this  
Followers 0
MickeyBob

Real number comparison

13 posts in this topic

How do you compare two floating point numbers? I've tried all the versions of the symbol comparison instructions and none seem to work. Either there is another way to do it or I'm doing something wrong in my code. Tx, MickeyBob

Share this post


Link to post
Share on other sites
Duh, =F, <F, >F, etc. I have it working now. Sorry to waste your time. Tx, MickeyBob

Share this post


Link to post
Share on other sites
Dang it. That's one that I actually knew. Maybe next time :) Good job figuring it out! Tig

Share this post


Link to post
Share on other sites
You guys are really becoming CJ whizs!

Share this post


Link to post
Share on other sites
Since you guys are so disappointed, let me ask another question then.... I want to initialize a DM register with a floating-point number at powerup/restart. How do I put a floating-point literal into a DM register? Can't seem to use some version of the MOV instruction. I've thought about using the binary to floating point conversion instruction [i.e., FLT (452)]. More general question, how do you enter a floating-point literal as an operand? Tx, MickeyBob

Share this post


Link to post
Share on other sites
Take your new Symbol and Floating Point Divide by a new Symbol set to One. The result operand will take on the Floating Point Value of the Symbol.

Share this post


Link to post
Share on other sites
Here's another way if you don't want to use a predefined number symbol.... P_First_Cycle ---[ ]----------[*F(456)          ] A200.11         [ +1234567653.322 ]                 [ +1              ]                 [ D26000         ] Oh and just another little tip.... say you want to copy/mov a floating point number..then use the MOVL (move long) instruction remember the floating pt number is two words.....

Share this post


Link to post
Share on other sites
Yea MickeyBob getting to be pretty smart at this Omron stuff. Happen to know him personally, and he is about as good as they come.

Share this post


Link to post
Share on other sites
Tx guys. Those are just the ticket! The symbol works very well. It even eliminates the need to write the floating-point value to the DM register in my case. Tx for the quick responses. MickeyBob

Share this post


Link to post
Share on other sites
I've tried to use the *F(456) instruction with floating-point values directly and with symbols to initialize a DM register but CX-Programmer won't accept either. I also tried it with +F(454) but get the same basic results. Attached is a screen shot of my rung. The first operand is a symbol, defined as a number and has literal value '0.0'. CX-Programmer generates an "ERROR: Operand 1 Invalid IEEE Floating Point format at rung 1(6, 1)" Any insights would be greatly appreciated. Tx, MickeyBob

Share this post


Link to post
Share on other sites
OK... I tried and got the same results...after doing a little research, I think the answer lies in the below discussion, but I'm not enough of a mathematician to explain why...

Share this post


Link to post
Share on other sites
If you ever want initialise a float to a zero value then I have found that moving a 0 in does the trick....But because it is a doulbe length use the MOVL function....

Share this post


Link to post
Share on other sites
Yeah, I thought about that. Call me anal but I hate mixing integers with floats eventhough they are binaryly (new word) the same. I believed I tried other floating-point literals and some worked and other didn't. I can't recall off the top of my head which floats literals worked and which didn't. Thanks for the feedback. MickeyBob

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0