BasicMicro - Forums

www.basicmicro.com
It is currently Mon May 21, 2012 12:28 am

All times are UTC - 8 hours [ DST ]




Post new topic Reply to topic  [ 8 posts ] 
Author Message
 Post subject: Nano math functions
PostPosted: Mon Nov 08, 2010 11:54 am 
Offline
Guru

Joined: Fri Nov 13, 2009 10:28 am
Posts: 82
Location: Reno, Nevada
Is it possible to multiply a number ( 4000 * .05) using 1.0.0.29 IDE?

_________________
Harley


Top
 Profile  
 
 Post subject: Re: Nano math functions
PostPosted: Mon Nov 08, 2010 5:46 pm 
Offline
Master

Joined: Sun Aug 17, 2008 5:26 pm
Posts: 798
Location: CA bay Area
You are still using 1.0.0.29?! :o Are you reporting a problem?
You should be able to do this, the ".05" is floating point, and Studio is one of the few free BASICs that does 32-bit floating point math.
Check the Math chapter in the new reference manual at
http://www.basicmicro.com/Downloads_ep_43.html
Later.

_________________
kenjj
http://blog.basicmicro.com/
http://kjennejohn.wordpress.com/


Top
 Profile  
 
 Post subject: Re: Nano math functions
PostPosted: Tue Nov 09, 2010 9:15 am 
Offline
Guru

Joined: Fri Nov 13, 2009 10:28 am
Posts: 82
Location: Reno, Nevada
I am using 1.0.0.29 as I went to the 2.0.0.0 ide, but then had errors with the pulsin command. I then reverted back to the 29 version until the 2.0.0.5 version is out and has the pulsin problems taken care of. This was on one of my previous posts. I will check out the manual as maybe I don't have the latest. The math functions regarding floating point were kind of vague and I didn't have much luck with implementing them. Maybe the new manual will be clearer and have some examples.
I checked out the new manual and the only thing I found is that it states that floating math is supported with no directions on its use. Maybe I should know how to do this, but I haven't been able to and some simple examples would be helpful. I may not be able to use the floating point math as it states that it is processor intensive and it may slow down the program too much. I am monitoring an rc transmitter stick and the outputs must be very fast. If I have missed something in the manual please let me know. Thanks.

_________________
Harley


Top
 Profile  
 
 Post subject: Re: Nano math functions
PostPosted: Tue Nov 09, 2010 10:21 am 
Offline
Master

Joined: Tue Nov 21, 2006 9:34 am
Posts: 527
2...5 is out!

There are two operators that appear in the precedence tables but are not described elsewhere TOINT, TOFLOAT.
You can do things like:
Code:
x   var word
x = toint(0.5 * tofloat 400)
serout s_out, i9600, [dec x,  13]


Kurt


Top
 Profile  
 
 Post subject: Re: Nano math functions
PostPosted: Tue Nov 09, 2010 11:30 am 
Offline
Guru

Joined: Fri Nov 13, 2009 10:28 am
Posts: 82
Location: Reno, Nevada
Thanks Kurt. I'll download the .5 ide and it looks like the code you provided may just do the job for me

I tried the following code and received the listed error. ccwval is defined as a var word. This is the error I always seem to get.

ccwval = toint(.05 * tofloat 4000)
Error: FILE C:\PROGRAM FILES\BASICMICRO\SERVOEPAADJ.BAS(LINE 67) : [TOKEN 05] : Unexpected token type

UPDATE! I just realized that the error occurs if the leading zero is not included. Using 0.05 now compiles without error!
ccwval = toint(0.05 * tofloat 4000)

_________________
Harley


Top
 Profile  
 
 Post subject: Re: Nano math functions
PostPosted: Tue Nov 09, 2010 12:46 pm 
Offline
Master

Joined: Tue Jun 22, 2010 1:15 pm
Posts: 203
Ha!

I just "discovered" toint and tofloat last night! I saw it used in the manual, but no explanation. They work basically as casts, like in C.

Some of last night's code:

Code:
index = toint((tofloat FIRLValue) / 5.12)   ; Sharp IR Limit value to <200 values
FIRLactual = scantable(index)   ; Convert A/D to measurement


Alan KM6VV

KurtEck wrote:
2...5 is out!

There are two operators that appear in the precedence tables but are not described elsewhere TOINT, TOFLOAT.
You can do things like:
Code:
x   var word
x = toint(0.5 * tofloat 400)
serout s_out, i9600, [dec x,  13]


Kurt

_________________
Visit:
http://groups.yahoo.com/group/SherlineCNC/
http://tech.groups.yahoo.com/group/HexapodRobotIK/


Top
 Profile  
 
 Post subject: Re: Nano math functions
PostPosted: Tue Nov 09, 2010 7:08 pm 
Offline
Guru

Joined: Sun Jan 03, 2010 8:01 am
Posts: 55
Location: Eau Claire, WI
I don't know if this will help but I've been working on math conversions using floating numbers; here are my code examples:

PS: I also found the issues with having to use 0.5 vs .5 and I am using 1.0.0.35

; B,D and Z are reserved; they cannot be declared as variables
X VAR FLOAT
Y VAR FLOAT
A VAR FLOAT

PI FCON 3.14
X= 1.5 * -0.5
Y= 2.234

A= PI * X

DEBUG ["The value of PI is ", REAL PI\3] ;The \3 will round the number to 3 decimal places
DEBUG [13]
DEBUG ["The value of X is ", REAL X\3]
DEBUG [13]
DEBUG ["The value of Y is ", REAL Y\3]
DEBUG [13]
DEBUG ["The value of A is ", REAL A\3]
;or you can combine a CR with this example DEBUG ["The value of PI is ", REAL PI\3,13]


Top
 Profile  
 
 Post subject: Re: Nano math functions
PostPosted: Wed Nov 10, 2010 10:06 am 
Offline
Site Admin
User avatar

Joined: Thu Mar 01, 2001 11:00 am
Posts: 903
Location: Temecula, CA
Just a note, the \3 in your code will not round, it truncates.

_________________
Tech Support
Basic Micro - Robotic Technology Evolved


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 8 posts ] 

All times are UTC - 8 hours [ DST ]


Who is online

Users browsing this forum: No registered users and 1 guest


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

Jump to:  
cron
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group

phpBB SEO