Page 2 of 3

Re: NXC: functions with different numbers of parameters?

Posted: 05 Jul 2012, 22:03
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));

Re: NXC: functions with different numbers of parameters?

Posted: 08 Jul 2012, 19:13
by afanofosc
NXC does not currently support scientific notation for numeric constants.

John Hansen

Re: NXC: functions with different numbers of parameters?

Posted: 08 Jul 2012, 20:02
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))
#----------------------------------------------------------

Re: NXC: functions with different numbers of parameters?

Posted: 09 Jul 2012, 18:15
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

Re: NXC: functions with different numbers of parameters?

Posted: 09 Jul 2012, 18:58
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

Re: NXC: functions with different numbers of parameters?

Posted: 11 Jul 2012, 09:04
by HaWe
is there any reason why assigning of large floating point numbers is impossible at all (either which notation) ?

Re: NXC: functions with different numbers of parameters?

Posted: 11 Jul 2012, 12:17
by linusa
-10000000000000000000000000000000000000 is of type integer, maybe try -10000000000000000000000000000000000000.0 or -10000000000000000000000000000000000000.0f

Re: NXC: functions with different numbers of parameters?

Posted: 11 Jul 2012, 14:59
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

Re: NXC: functions with different numbers of parameters?

Posted: 12 Jul 2012, 06:57
by HaWe
peculiar:
formerly, the error msg refers to the system temp directory -
now the error refers to my working directory...

Re: NXC: functions with different numbers of parameters?

Posted: 25 Jul 2012, 14:18
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