Float question
bambino69
Posts: 126
in Propeller 2
The Float command in spin is easy enough, but round and truncate have got me scratching my head.
How do you convert floats back to integer in spin?
Surely this has come up before. Any links to where this has allready been discussed?
How do you convert floats back to integer in spin?
Surely this has come up before. Any links to where this has allready been discussed?
Comments
As far as I know, the "float" command in spin is only used at compile time. To convert floats and integers at runtime requires a dedicated object such as F32.
I'm not aware of a F32 equivalent for Spin2.
I've searched the Propeller 2 forum on this topic and all I've learned is the P2 doesn't have built in floating point hardware (at least the thread from 2014 said this).
Hopefully someone more knowledgeable will set us straight.
I've attached in case you don't have it on your system.
Doc
Differences are the ENCOD operation returns different values to P1.
SAR and SCA were substituted.
IIRC thats all I changed and it seems to work Ok.
Indeed. Or flexprop BASIC; that also has full floating point support, and it's got a very simple syntax:
😎👍👍
I've registered for the live forum this week. Y'all can take your best shot at me.
I love the spin language, and the prop ide will get sweeter everyday.
With the p1 it was all about time to market for me, and I didn't really get to play like I wanted to.
This time around I just want to keep it fun.
Learning another language at the same time I'm re-learning spin might put my lid in orbit.
But just like catalina, and c, and forth was to the p1, I do want to know where you guys are.
My pursuit at the moment is to maybe help update some p1 objects so I'm assuming these other Ide's would not benefit me
in that endeavor. Someone correct me if I'm wrong.
FlexProp can compile Spin 1 to run on the P2, so it saves some work in porting. This isn't a huge deal (porting from Spin 1 to Spin 2 is not difficult) but if you have a lot of Spin code and you don't want to do the mechanical work of changing keywords and putting parentheses in where you need to, it may save you some effort. The PASM parts of your code still have to be converted, since P1 and P2 have different assembly languages.
Different languages do have different strengths. If you're doing a lot of floating point work, using a language like C or BASIC that has built in floating point lets you write things like "x + y * z" instead of "f.FAdd(x, F.FMul(y, z))". With FlexProp you can even mix the Spin with BASIC or C, so you could write the high level floating point part in BASIC while leaving the low level device drivers in Spin.
FloatMath.spin compiles without errors in FlexSpin and works on a P2, as far as I can tell.