Shop OBEX P1 Docs P2 Docs Learn Events
fmax and fmin problems in Propeller C — Parallax Forums

fmax and fmin problems in Propeller C

ChrisL8ChrisL8 Posts: 129
edited 2014-08-01 09:48 in Propeller 1
Simple question, why won't this C code build in SimpleIDE?
#include "simpletools.h"
int main()
{
   char *ptr;
   double myNumber = strtod("3.5", &ptr);
   double newNumber = fmin(myNumber, 2.5);
   print("%f\n", newNumber);
}

This is the error I get:
propeller-elf-gcc.exe -v GCC 4.6.1 (propellergcc_v1_0_0_2162)
...
c:/program files (x86)/simpleide/propeller-gcc/bin/../lib/gcc/propeller-elf/4.6.1/../../../../propeller-elf/lib/cmm/short-doubles\libm.a(s_fmin.o): In function `_fmin':
(.text+0x1e): undefined reference to `___signbit'
c:/program files (x86)/simpleide/propeller-gcc/bin/../lib/gcc/propeller-elf/4.6.1/../../../../propeller-elf/lib/cmm/short-doubles\libm.a(s_fmin.o): In function `_fmin':
(.text+0x26): undefined reference to `___signbit'
c:/program files (x86)/simpleide/propeller-gcc/bin/../lib/gcc/propeller-elf/4.6.1/../../../../propeller-elf/lib/cmm/short-doubles\libm.a(s_fmin.o): In function `_fmin':
(.text+0x30): undefined reference to `___signbit'
collect2: ld returned 1 exit status
Done. Build Failed!


Check source for bad function call or global variable name __signbit'
c:/program files (x86)/simpleide/propeller-gcc/bin/../lib/gcc/propeller-elf/4.6.1/../../../../propeller-elf/lib/cmm/short-doubles\libm.a(s_fmin.o): In function `_fmin':
(.text+0x26)

If I change myNumber to a straight declaration like:
double myNumber = 3.5;
then it works fine.

If I don't try to pass newNumber to a function it also works fine.

What I am trying to do is take numbers coming in over the serial port,
convert them to doubles with strtod,
then compare them with existing numbers and pick the larger and smaller of the two,
and finally use these numbers in other functions.

It appears though that if I try to use fmin or fmax on a double that comes out of strtod I cannot use the output in any function without errors from the compiler.

If what I am trying is impossible, please feel free to offer other directions, such as:
C++?
Another format to pass data over the serial port besides strings?
Another way to get the smaller and larger of two floats besides fmin & fmax?

Thank you!

Comments

  • ChrisL8ChrisL8 Posts: 129
    edited 2014-07-31 07:44
    I guess this is the obvious solution:
    #include "simpletools.h"
    int main()
    {
      char *ptr;
      double myNumber = strtod("3.5", &ptr);
      //double newNumber = fmin(myNumber, 2.5);
      double newNumber = myNumber;
      if (2.5 < myNumber)
      newNumber = 2.5;
      print("%f\n", newNumber);
    }
    
  • ReinhardReinhard Posts: 489
    edited 2014-07-31 07:55
    too late for me ;-)
    Just wanted to suggest the same solution
    btw. the problem with fmin can I see also.
  • ersmithersmith Posts: 6,054
    edited 2014-08-01 09:48
    There's a function (__signbit) missing from the math libraries. Thanks for reporting this! it's fixed in google code, so the next release should have this bug fix as well.
Sign In or Register to comment.