View unanswered posts | View active topics It is currently Tue Oct 21, 2014 7:57 am






Reply to topic  [ 6 posts ] 
Where is type double 
Author Message
Expert
User avatar

Joined: Tue Oct 14, 2008 7:16 pm
Posts: 171
Location: Investigating an unidentified ship sighted in Sector 31428
Post Where is type double
I'm trying to create a speed scaling function based on a cubic regression but it seems that firstly the data type double does not exist but none of the other data types are large enough to hold the numbers. On top of that the provided data types are not what a C or C++ programmer knows them to be and this is not explictly stated. Indeed type int should be large enough to hold the numbers I'm working with but it appears not to be.

Is there a way around this or a way to redefine the size of the data types?
:breakcomputer:

_________________
Captain, Head programmer, School of the Arts, Silverbots Robtics Team #2890
Code:
using namespace System;
using namespace Genius;
using namespace Personality;
public ref class Nerd : Geek, IAnserable
{
    Geek::Type brainMode = Geek::Type::Programmer;
}


Tue Oct 14, 2008 7:25 pm
Profile
Creator
Creator

Joined: Fri Feb 09, 2007 9:21 am
Posts: 615
Post Re: Where is type double
ROBOTC supports the following standard C data types:
char
short
int
long
float

ROBOTC deviates from standard C in that all variables are signed. Unsigned types are currently not supported. ROBOTC will accept the "unsigned" keyword but should generate a compiler warning message indicating that it is ignored.

In the C language, the size of an "int" is implementation specific. In the case of ROBOTC, "int" variables are 16-bits. I realize that this may not be the best choice for the NXT which has a native 32-bit CPU. But ROBOTC runs on many platforms / CPUs, most of which are 8-bit hardware CPUs, and 16-bit was used. Use of 16-bit "int" is farily common on embedded systems; for example, an "int" on the VEX CPU is 16-bits. "int" on Atmel AVR, Microchip PICs, Renesas H8 series, Zilog Z8 series are all 16-bits.

A float is 32-bits total. 8-bit exponent and 24-bit mantissa. Doubles are not supported in ROBOTC.

Hope above helps. Perhaps "long" or "float" will meet your needs.


Tue Oct 14, 2008 10:08 pm
Profile
Expert
User avatar

Joined: Tue Oct 14, 2008 7:16 pm
Posts: 171
Location: Investigating an unidentified ship sighted in Sector 31428
Post Re: Where is type double
That I'm afraid is part of the problem. Even though I'm using float there seems to be cutting off the calculation. Is there a limit on the size of the calculations possible. For example the function is supposed to cube the value from the joysticks but the number returned is far less than it should be (I tried this with just a stand alone varriable and calculation) even when stored in a float varriable.

You may want to point out in the documentation which data types are supported and state their limits. Also if I may add, you may want to consider adding a virtual testing platform in future versions so that programmers can test code without a robot present.

_________________
Captain, Head programmer, School of the Arts, Silverbots Robtics Team #2890
Code:
using namespace System;
using namespace Genius;
using namespace Personality;
public ref class Nerd : Geek, IAnserable
{
    Geek::Type brainMode = Geek::Type::Programmer;
}


Wed Oct 15, 2008 6:57 pm
Profile
Professor

Joined: Fri Sep 19, 2008 1:22 am
Posts: 200
Post Re: Where is type double
I suggest using longs which are 32bit integers. You will need to be careful to perform your math opporations in an order that will avoid overflow but 32 bits integers are capable of handling 128^3.

Feel free to post your current code if you would like help.

_________________
Jeff McBride
Benson Robotics Club


Wed Oct 15, 2008 8:06 pm
Profile
Guru
User avatar

Joined: Sat Mar 01, 2008 12:52 pm
Posts: 1030
Post Re: Where is type double
I think RobotC has to be customized to the 32 bit ARM7 processor.
It is not suitable to use a 8 bit compiler model for a 32 bit processor.
Get rid of the old stuff.

It's like if I drove my 911 always in the first gear - with tightened handbrake. :twisted:

_________________
regards,
HaWe aka Ford
#define S sqrt(t+2*i*i)<2
#define F(a,b) for(a=0;a<b;++a)
float x,y,r,i,s,j,t,n;task main(){F(y,64){F(x,99){r=i=t=0;s=x/33-2;j=y/32-1;F(n,50&S){t=r*r-i*i;i=2*r*i+j;r=t+s;}if(S){PutPixel(x,y);}}}while(1)}


Last edited by Ford Prefect on Thu Oct 16, 2008 6:01 am, edited 1 time in total.



Thu Oct 16, 2008 4:04 am
Profile
Creator
Creator

Joined: Fri Feb 09, 2007 9:21 am
Posts: 615
Post Re: Where is type double
Atlantisbase wrote:
That I'm afraid is part of the problem. Even though I'm using float there seems to be cutting off the calculation. Is there a limit on the size of the calculations possible. For example the function is supposed to cube the value from the joysticks but the number returned is far less than it should be (I tried this with just a stand alone varriable and calculation) even when stored in a float varriable.

You may want to point out in the documentation which data types are supported and state their limits. Also if I may add, you may want to consider adding a virtual testing platform in future versions so that programmers can test code without a robot present.

I am not aware of any problems with ROBOTC's "number precision". I just tried the following test program and examined the output in the debugger window to confirm this.
Code:
task main()
{
  float fTestBig[32];
  float fTestSmall[32];
  long  lTest[32];


  fTestBig[0] = 2;
  fTestSmall[0] = 1;
  lTest[0] = 2;
  for (int i = 1; i < 32; ++i)
  {
    fTestBig[i] = fTestBig[i - 1] * 2;
    fTestSmall[i] = fTestSmall[i - 1] / 10;
    lTest[i] = lTest[i - 1] * 2;
  }
}

There may be a bug in ROBOTC's expression calculation / compiler. BUt I suspect what you've encountered is a simplification that ROBOTC does in the debugger display of float numbers. For very small numbers in the range 0.000001 to 0.001 it will display as zero rather than in "scientific notation". The rationale behind this was to limit display precision to four or five decimal digits and avoid having to explain scientific notation to novices.

If you run the above program and look at the results in the debugger window, you'll see the display for "fTestSmall" as values:
1
0.1
0.01
0.001
0.0001
0
0
1.0000e-006
1.0000e-007
1.0000e-008
. . .
If you use the "nxtDisplayTextLine( xx, "%f", variable):" to display a value on the NXT LCD you'll see that the internal results are what's expected. Or you can use the Debugger "Hexadecimal display" to get the variables displayed in hex.

If you still think there are errors in calculations, then please post again.


Thu Oct 16, 2008 5:36 am
Profile
Display posts from previous:  Sort by  
Reply to topic   [ 6 posts ] 

Who is online

Users browsing this forum: No registered users 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:  
cron



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