Ad Widget

Collapse

1.1beta8 problem with float

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Paul Makeev
    Junior Member
    • Apr 2006
    • 5

    #1

    1.1beta8 problem with float

    I have a problem with loading FLOAT values to zabbix_serverd.
    Here is the value: 2.70532e+09; item type is FLOAT.
    Server reports:
    Type of received value [2.70532e+09] is not sutable for [nfc.stat[records]@xxxx]

    What is the GOOD FLOAT format for zabbix? If i load INTs into FLOAT item,
    everything goes Ok, but i want to use FLOAT, since we run both 320bit and 64-bit platforms.

    tia
    Last edited by Paul Makeev; 06-04-2006, 15:16.
  • Paul Makeev
    Junior Member
    • Apr 2006
    • 5

    #2
    apparently problem happens to be caused by the code in the is_double
    function, module libs/zbxcommon/misc.c

    The FLOAT type used in zabbix is not REAL FLOAT (sorry for pun), but FIXED one. Other function (eg diff) would not work for me too. Some interference required to make zabbix understand FLOAT properly.

    Also, i've run into different problem: zabbix sometimes could not properly evaluate speed
    (delta/sec) for big integer values.

    Comment

    • Paul Makeev
      Junior Member
      • Apr 2006
      • 5

      #3
      patches

      with the little help from my C-speaking friends i've replaced two functions in module misc.c now everything works ok for me with float input and invalid delta/speed (sorry, it was float, not int64 problem too).

      cmp_double is correct now. Used the function from



      #define maxUlps 4

      int cmp_double(double a,double b)
      {
      long long int aInt, bInt, intDiff;
      aInt = *(long long int*)&a;
      if (aInt < 0)
      aInt = 0x8000000000000000L - aInt;
      bInt = *(long long int*)&b;
      if (bInt < 0)
      bInt = 0x8000000000000000L - bInt;
      intDiff=llabs(aInt-bInt);
      if (intDiff <= maxUlps)
      return 1;
      return 0;
      }



      int is_double(char *str)
      {
      const char *endstr = str + strlen(str);
      char *endptr = NULL;
      double x = strtod(str, &endptr);
      if(endptr == str || errno != 0) return FAIL;
      if (endptr == endstr) return SUCCEED;
      return FAIL;
      }

      Comment

      • Alexei
        Founder, CEO
        Zabbix Certified Trainer
        Zabbix Certified SpecialistZabbix Certified Professional
        • Sep 2004
        • 5654

        #4
        Why change cmp_double?
        Alexei Vladishev
        Creator of Zabbix, Product manager
        New York | Tokyo | Riga
        My Twitter

        Comment

        • Paul Makeev
          Junior Member
          • Apr 2006
          • 5

          #5
          because original code would not work well with small numbers (which are comparable to epsilon), or big ones (when epsilon is less than increment in float numbers range). The step i speak about is delta in float when we increment the lowest bit in mantissa. You can read more detailed discussion here:

          Comment

          • Paul Makeev
            Junior Member
            • Apr 2006
            • 5

            #6
            I ought to say the code for double comparison could be machine-dependent.
            It should work OK for IEEE-754 compliant architecture (will check on Sparc).

            Comment

            • Alexei
              Founder, CEO
              Zabbix Certified Trainer
              Zabbix Certified SpecialistZabbix Certified Professional
              • Sep 2004
              • 5654

              #7
              Originally posted by Paul Makeev
              int is_double(char *str)
              {
              const char *endstr = str + strlen(str);
              char *endptr = NULL;
              double x = strtod(str, &endptr);
              if(endptr == str || errno != 0) return FAIL;
              if (endptr == endstr) return SUCCEED;
              return FAIL;
              }

              The patch is incorrect. Is does not work under RedHat AS3. Reverted to original one.
              Alexei Vladishev
              Creator of Zabbix, Product manager
              New York | Tokyo | Riga
              My Twitter

              Comment

              Working...