Logo Search packages:      
Sourcecode: libnl version File versions  Download package

long nl_prob2int ( const char *  str  ) 

Convert a character string to a probability

  • str probability encoded as character string
Converts the specified probability as character to the corresponding probability number.

Supported formats are:

  • 0.0-1.0
  • 0-100%

Returns:
The probability relative to NL_PROB_MIN and NL_PROB_MAX

Definition at line 239 of file utils.c.

References NL_PROB_MAX.

{
      char *p;
      double d = strtod(str, &p);

      if (p == str)
            return -1;

      if (d > 1.0)
            d /= 100.0f;

      if (d > 1.0f || d < 0.0f)
            return -1;

      if (*p && strcmp(p, "%") != 0)
            return -1;

      return rint(d * NL_PROB_MAX);
}


Generated by  Doxygen 1.6.0   Back to index