NXC: functions with different numbers of parameters?

Discussion specific to NXT-G, NXC, NBC, RobotC, Lejos, and more.
HaWe
Posts: 2500
Joined: 04 Nov 2014, 19:00

Re: NXC: functions with different numbers of parameters?

Post by HaWe »

spillerec wrote:but it seems like it is the compiler which easily messes up with scientific notification.
yes, indeed, it seems to be a compiler bug, cause I also tried it by

Code: Select all

// #define FLT_MAX 1E37 
float FLT_MAX=1E37;

float max(float f1, float f2, float f3 = -FLT_MAX, float f4 = -FLT_MAX, float f5 = -FLT_MAX) {
  float flarr[5], f;
  flarr[0]=f1; flarr[1]=f2; flarr[2]=f3; flarr[3]=f4; flarr[4]=f5;
  f=ArrayMax( flarr, 0, 5 );
  return f;
}

task main() {
  NumOut(0,8, max(7.1, 12.4, 5.9, 18.6));   // if it works, then NumOut does not display floats!
  //NumOut(0,0, max(7.1, 12.4, 5.9, 1E+9));   // compiler error
  for(;;);
}
with a similar error msg.
# Error: Invalid floating point operation
File "c:\Temp\temp.nxc" ; line 5
# FLT_MAX float 9.99999999999999954E36
#----------------------------------------------------------
# Error: Error parsing expression: FLT_MAX |
File "c:\Temp\temp.nxc" ; line 14
#
#----------------------------------------------------------
2 errors during compilation
it's not just always like the max thing passing the same vatiable types, what actually my goal is - it's more also having different numbers of parameters of different types, like how it is possible in the TextOut example:

Code: Select all

TextOut( char x, char y, string s(, optional: int textstyle));
Last edited by HaWe on 12 Jul 2012, 14:31, edited 1 time in total.
afanofosc
Site Admin
Posts: 1256
Joined: 26 Sep 2010, 19:36
Location: Nashville, TN
Contact:

Re: NXC: functions with different numbers of parameters?

Post by afanofosc »

NXC does not currently support scientific notation for numeric constants.

John Hansen
Multi-platform LEGO MINDSTORMS programming
http://bricxcc.sourceforge.net/
HaWe
Posts: 2500
Joined: 04 Nov 2014, 19:00

Re: NXC: functions with different numbers of parameters?

Post by HaWe »

ok, but this also doesn't work - what's wrong with this?

Code: Select all

#define FLT_MAX 10000000000000000000000000000000000000

float max(float f1, float f2, float f3 = -FLT_MAX, float f4 = -FLT_MAX, float f5 = -FLT_MAX) {
  float flarr[5];
  flarr[0]=f1; flarr[1]=f2; flarr[2]=f3; flarr[3]=f4; flarr[4]=f5;
  
  return ArrayMax( flarr, 0, 5 );
}

task main() {

  NumOut(0,8, max(7.1, 12.4, 5.9, 18.6));   // NumOut does not display floats, just ints!
  for(;;);

}
# Error: Invalid parameter syntax with default values
File "c:\Temp\temp.nxc" ; line 5
# float max(float f1, float f2, float f3 = -9.99999999999999954E36, f
#----------------------------------------------------------
# Error: Not valid for a prototype
File "c:\Temp\temp.nxc" ; line 6
# f
#----------------------------------------------------------
# Error: Undefined Identifier f4
File "c:\Temp\temp.nxc" ; line 7
# flarr[0]=f1; flarr[1]=f2; flarr[2]=f3; flarr[3]=f4;
#----------------------------------------------------------
# Error: Undefined Identifier f5
File "c:\Temp\temp.nxc" ; line 7
# flarr[0]=f1; flarr[1]=f2; flarr[2]=f3; flarr[3]=f4; flarr[4]=f5;
#----------------------------------------------------------
# Error: Undefined Identifier f5
File "c:\Temp\temp.nxc" ; line 9
# r
#----------------------------------------------------------
# Error: Too many arguments
File "c:\Temp\temp.nxc" ; line 14
# NumOut(0,8, max(7.1, 12.4, 5.9, 18.6)
#----------------------------------------------------------
# Error: ")" expected
File "c:\Temp\temp.nxc" ; line 14
# NumOut(0,8, max(7.1, 12.4, 5.9, 18.6)
#----------------------------------------------------------
# Error: ')' expected
File "c:\Temp\temp.nxc" ; line 14
# NumOut(0,8, max(7.1, 12.4, 5.9, 18.6)
#----------------------------------------------------------
# Error: ';' expected
File "c:\Temp\temp.nxc" ; line 14
# NumOut(0,8, max(7.1, 12.4, 5.9, 18.6))
#----------------------------------------------------------
afanofosc
Site Admin
Posts: 1256
Joined: 26 Sep 2010, 19:36
Location: Nashville, TN
Contact:

Re: NXC: functions with different numbers of parameters?

Post by afanofosc »

It looks like the preprocessor is causing your very large constant to be represented as number in exponential notation which the NXC compiler does not currently support.

Does this work?

Code: Select all

float max(float f1, float f2, float f3 = -FLT_MAX, float f4 = -10000000000000000000000000000000000000, float f5 = -10000000000000000000000000000000000000) {
  float flarr[5];
  flarr[0]=f1; flarr[1]=f2; flarr[2]=f3; flarr[3]=f4; flarr[4]=f5;
  
  return ArrayMax( flarr, 0, 5 );
}
John Hansen
Multi-platform LEGO MINDSTORMS programming
http://bricxcc.sourceforge.net/
HaWe
Posts: 2500
Joined: 04 Nov 2014, 19:00

Re: NXC: functions with different numbers of parameters?

Post by HaWe »

unfortunately, no

Code: Select all

float max(float f1, float f2, float f3 = -10000000000000000000000000000000000000,
                              float f4 = -10000000000000000000000000000000000000,
                              float f5 = -10000000000000000000000000000000000000) {
  float flarr[5];
  flarr[0]=f1; flarr[1]=f2; flarr[2]=f3; flarr[3]=f4; flarr[4]=f5;
  
  return ArrayMax( flarr, 0, 5 );
}

task main() {

  NumOut(0,8, max(7.1, 12.4, 5.9, 18.6));   // if it incidentally works, then  NumOut does not display floats!
  for(;;);

}
# Error: Invalid floating point operation
File "c:\Temp\temp.nxc" ; line 14
# mov __max_7qG2_f5_7qG2_000, -10000000000000000000000000000000000000
#----------------------------------------------------------
1 errors during compilation
HaWe
Posts: 2500
Joined: 04 Nov 2014, 19:00

Re: NXC: functions with different numbers of parameters?

Post by HaWe »

is there any reason why assigning of large floating point numbers is impossible at all (either which notation) ?
linusa
Posts: 228
Joined: 16 Oct 2010, 11:44
Location: Aachen, Germany
Contact:

Re: NXC: functions with different numbers of parameters?

Post by linusa »

-10000000000000000000000000000000000000 is of type integer, maybe try -10000000000000000000000000000000000000.0 or -10000000000000000000000000000000000000.0f
RWTH - Mindstorms NXT Toolbox for MATLAB
state of the art in nxt remote control programming
http://www.mindstorms.rwth-aachen.de
MotorControl now also in Python, .net, and Mathematica
HaWe
Posts: 2500
Joined: 04 Nov 2014, 19:00

Re: NXC: functions with different numbers of parameters?

Post by HaWe »

float f3 = -10000000000000000000000000000000000000.0f is invalid syntax,

if I try

Code: Select all

//#define FLT_MAX 1E37
//#define FLT_MAX 10000000000000000000000000000000000000

float max(float f1, float f2, float f3 = -10000000000000000000000000000000000000.0,
                              float f4 = -10000000000000000000000000000000000000.0,
                              float f5 = -10000000000000000000000000000000000000.0) {
  float flarr[5];
  flarr[0]=f1; flarr[1]=f2; flarr[2]=f3; flarr[3]=f4; flarr[4]=f5;
  
  return ArrayMax( flarr, 0, 5 );
}

task main() {
  NumOut(0,8, max(7.1, 12.4, 5.9, 18.6));   // if it incidentally works, then  NumOut does not display floats!
  for(;;);
}
again the same error occurs:
# Error: Invalid floating point operation
File "G:\Akten\Programmierung\NXC\Test\multparamstest.nxc" ; line 16
# mov __max_7qG2_f5_7qG2_000, -10000000000000000000000000000000000000.0
#----------------------------------------------------------
1 errors during compilation
HaWe
Posts: 2500
Joined: 04 Nov 2014, 19:00

Re: NXC: functions with different numbers of parameters?

Post by HaWe »

peculiar:
formerly, the error msg refers to the system temp directory -
now the error refers to my working directory...
afanofosc
Site Admin
Posts: 1256
Joined: 26 Sep 2010, 19:36
Location: Nashville, TN
Contact:

Re: NXC: functions with different numbers of parameters?

Post by afanofosc »

Yesterday I uploaded a new test release which should fix most of the problems Doc was experiencing with floating point constants/exponential notation.

http://bricxcc.sourceforge.net/test_releases/

John Hansen
Multi-platform LEGO MINDSTORMS programming
http://bricxcc.sourceforge.net/
Post Reply

Who is online

Users browsing this forum: Ahrefs [Bot] and 18 guests