Number Utility

This chapter describes APIs of the utility for number processing.

1. pfmNumAssign

Assigns a PfmNumber parameter to another PfmNumber parameter.

  • Prototype

    long pfmNumAssign(PfmNumber *x, PfmNumber y);
  • Parameters

    Parameter Description

    *x (output)

    Assignment result value.

    y (input)

    Input value.

  • Return values

    Return Value Description

    RC_NRM

    This API is executed successfully.

    RC_ERR

    This API is not executed successfully.

  • Example

    rc = pfmNumAssign(&a, b);
    if(rc != RC_NRM) {
       PFM_ERR("%s", pfmNumErrorMsg());
       /* Or, PFM_ERR("%s", pfmUtilGetErrorMsg()); */
       return RC_ERR;
    }
    /* a = b */

2. pfmNumToLong

Converts a PfmNumber value to a Long value.

  • Prototype

    long pfmNumToLong(long *x, PfmNumber y);
  • Parameters

    Parameter Description

    *x (output)

    Value converted to Long.

    y (input)

    PfmNumber value.

  • Return values

    Return Value Description

    RC_NRM

    This API is executed successfully.

    RC_ERR

    This API is not executed successfully.

  • Example

    long     num;
    
    a = PFMNUM_ONE;
    rc = pfmNumToLong(&num, a);
    if(rc != RC_NRM) {
       PFM_ERR("%s", pfmNumErrorMsg());
       /* Or, PFM_ERR("%s", pfmUtilGetErrorMsg()); */
       return RC_ERR;
    }
    /* num = 1 */

3. pfmNumGetFromLong

Converts a Long value to a PfmNumber value.

  • Prototype

    long pfmNumGetFromLong(PfmNumber *x, long y);
  • Parameters

    Parameter Description

    *x (output)

    Value converted to PfmNumber.

    y (input)

    Long value.

  • Return values

    Return Value Description

    RC_NRM

    This API is executed successfully.

    RC_ERR

    This API is not executed successfully.

  • Example

    PfmNumber     a;
    long          num  =  123;
    
    rc = pfmNumGetFromLong(&a, num);
    if(rc != RC_NRM) {
       PFM_ERR("%s", pfmNumErrorMsg());
       /* Or, PFM_ERR("%s", pfmUtilGetErrorMsg()); */
       return RC_ERR;
    }
    /* a = 123 */

4. pfmNumToDouble

Converts a PfmNumber value to a Double value.

  • Prototype

    long pfmNumToDouble(double *x, PfmNumber y);
  • Parameters

    Parameter Description

    *x (output)

    Value converted to Double.

    y (input)

    PfmNumber value.

  • Return values

    Return Value Description

    RC_NRM

    This API is executed successfully.

    RC_ERR

    This API is not executed successfully.

  • Example

    double     num;
    
    a = PFMNUM_ONE;
    rc = pfmNumToDouble(&num, a);
    if(rc != RC_NRM) {
       PFM_ERR("%s", pfmNumErrorMsg());
       /* Or, PFM_ERR("%s", pfmUtilGetErrorMsg()); */
       return RC_ERR;
    }
    /* num = 1.0 */

5. pfmNumGetFromDouble

Converts a Double value to a PfmNumber value.

  • Prototype

    long pfmNumGetFromDouble(PfmNumber *x, double y);
  • Parameters

    Parameter Description

    *x (output)

    Value converted to PfmNumber.

    y (input)

    Double value.

  • Return values

    Return Value Description

    RC_NRM

    This API is executed successfully.

    RC_ERR

    This API is not executed successfully.

  • Example

    PfmNumber     a;
    double        num  =  123.456;
    
    rc = pfmNumGetFromDouble(&a, num);
    if(rc != RC_NRM) {
       PFM_ERR("%s", pfmNumErrorMsg());
       /* Or, PFM_ERR("%s", pfmUtilGetErrorMsg()); */
       return RC_ERR;
    }

6. pfmNumGetFromDouble2

Rounds off a Double value and then converts it to a PfmNumber value.

  • Prototype

    long pfmNumGetFromDouble2(PfmNumber *x, double y, long precision);
  • Parameters

    Parameter Description

    *x (output)

    Value converted to PfmNumber.

    y (input)

    Double value.

    precision

    Rounding position.

  • Return values

    Return Value Description

    RC_NRM

    This API is executed successfully.

    RC_ERR

    This API is not executed successfully.

  • Example

    PfmNumber     a;
    double       num  =  123.456;
    
    rc = pfmNumGetFromDouble2(&a, num, 1);
    /* a = 123.5 */
    rc = pfmNumGetFromDouble2(&a, num, -1);
    /* a = 120 */
    
    if(rc != RC_NRM) {
       PFM_ERR("%s", pfmNumErrorMsg());
       /* Or, PFM_ERR("%s", pfmUtilGetErrorMsg()); */
       return RC_ERR;
    }

7. pfmNumGetFromStr

Converts a value expressed as a NULL-terminated string to a PfmNumber value.

  • Prototype

    long pfmNumGetFromStr(PfmNumber *x, char *str);
  • Parameters

    Parameter Description

    *x (output)

    Value converted to PfmNumber.

    *str (input)

    Input string.

  • Return values

    Return Value Description

    RC_NRM

    This API is executed successfully.

    RC_ERR

    This API is not executed successfully.

  • Example

    PfmNumber     n1;
    char     str[]  =  "1234.56789";
    
    rc = pfmNumGetFromStr (&n1, str);
    if(rc != RC_NRM) {
       PFM_ERR("%s", pfmNumErrorMsg());
       /* Or, PFM_ERR("%s", pfmUtilGetErrorMsg()); */
       return RC_ERR;
    }

8. pfmNumGetFromStrn

Reads a given length of an input string and then converts it to a PfmNumber value.

  • Prototype

    long pfmNumGetFromStrn(PfmNumber *x, char *str, long len);
  • Parameters

    Parameter Description

    *x (output)

    Value converted to PfmNumber.

    *str (input)

    Input string.

    len(input)

    Length of the input string.

  • Return values

    Return Value Description

    RC_NRM

    This API is executed successfully.

    RC_ERR

    This API is not executed successfully.

  • Example

    PfmNumber     n1;
    char    str[]  =  "1234.56789";
    
    rc = pfmNumGetFromStrn(&n1, str, strlen(str));
    if(rc != RC_NRM) {
       PFM_ERR("%s", pfmNumErrorMsg());
       /* Or, PFM_ERR("%s", pfmUtilGetErrorMsg()); */
       return RC_ERR;
    }
    /* n1 == 1234.56789 */
    
    rc = pfmNumGetFromStrn(&n1, str, 3);
    if(rc != RC_NRM) {
       PFM_ERR("%s", pfmNumErrorMsg());
       /* Or, PFM_ERR("%s", pfmUtilGetErrorMsg()); */
       return RC_ERR;
    }
    /* Reading 3 characters from str. That is, n1 == 123 */
    
    rc = pfmNumGetFromStrn(&n1, str, 20);
    if(rc != RC_NRM) {
       PFM_ERR("%s", pfmNumErrorMsg());
       /* Or, PFM_ERR("%s", pfmUtilGetErrorMsg()); */
       return RC_ERR;
    }
    /* Trying to read 20 characters from str, but it ends before that.
     That is, n1 == 1234.56789 */

9. pfmNumGetStrLPadZeroN

Converts a PfmNumber value to a Char value and then aligns it to the right. Blanks created during the alignment are padded with 0.

  • Prototype

    long pfmNumGetStrLPadZeroN(char *str, PfmNumber x, long buf_size);
  • Parameters

    Parameter Description

    *str (output)

    Value converted to Char.

    x (input)

    PfmNumber value.

    buf_size (input)

    Length of str.

  • Return values

    Return Value Description

    RC_NRM

    This API is executed successfully.

    RC_ERR

    This API is not executed successfully.

  • Example

    PfmNumber     a;
    char     str[256];
    
    a = PFMNUM_ONE;
    rc = pfmNumGetStrLPadZeroN(str, a, 5);
    if(rc != RC_NRM) {
       PFM_ERR("%s", pfmNumErrorMsg());
       /* Or, PFM_ERR("%s", pfmUtilGetErrorMsg()); */
       return RC_ERR;
    }
    /* str = "00001" */

10. pfmNumToStr

Converts a PfmNumber value to a Char string.

  • Prototype

    long pfmNumToStr (char *str, PfmNumber x);
  • Parameters

    Parameter Description

    *str (output)

    Value converted to Char.

    x (input)

    PfmNumber value.

  • Return values

    Return Value Description

    RC_NRM

    This API is executed successfully.

    RC_ERR

    This API is not executed successfully.

  • Example

    PfmNumber     a;
    char      str[256];
    
    a = PFMNUM_ONE;
    rc = pfmNumToStr(str, a);
    if(rc != RC_NRM) {
       PFM_ERR("%s", pfmNumErrorMsg());
       /* Or, PFM_ERR("%s", pfmUtilGetErrorMsg()); */
       return RC_ERR;
    }
    /* str = "1" */

11. pfmNumToStrn

Converts a PfmNumber value to a Char string with a given length.

  • Prototype

    long pfmNumToStrn(char *str, PfmNumber x, long buf_size);
  • Parameters

    Parameter Description

    *str (output)

    Value converted to Char.

    x (input)

    PfmNumber value.

    buf_size (input)

    Length of str.

  • Return values

    Return Value Description

    RC_NRM

    This API is executed successfully.

    RC_ERR

    This API is not executed successfully.

  • Example

    PfmNumber     a;
    char       str[256];
    
    a = PFMNUM_ONE;
    rc = pfmNumToStrn(str, a, 5);
    if(rc != RC_NRM) {
       PFM_ERR("%s", pfmNumErrorMsg());
       /* Or, PFM_ERR("%s", pfmUtilGetErrorMsg()); */
       return RC_ERR;
    }
    /* str = "1" */

12. pfmNumCmp

Compares two PfmNumber values.

  • Prototype

    long pfmNumCmp(PfmNumber x, PfmNumber y);
  • Parameters

    Parameter Description

    x (input)

    First PfmNumber value.

    y (input)

    Second PfmNumber value.

  • Return values

    Return Value Description

    0

    Means that x == y.

    Positive value

    Means that x > y.

    Negative value

    Means that x < y.

  • Example

    b = PFMNUM_ONE;
    
    if(pfmNumCmp(a, b) > 0) {
       PFM_DBG("a is greater than 1.");
       return RC_NRM;
    }

13. pfmNumCmpAbs

Compares absolute values of two PfmNumber values.

  • Prototype

    long pfmNumCmpAbs(PfmNumber x, PfmNumber y);
  • Parameters

    Parameter Description

    x (input)

    First PfmNumber value.

    y (input)

    Second PfmNumber value.

  • Return values

    Return Value Description

    0

    Means that |x| == |y|.

    Positive value

    Means that |x| > |y|.

    Negative value

    Means that |x| < |y|.

  • Example

    rc = pfmNumGetFromStr(&b, "3.14");
    if(rc != RC_NRM) {
       PFM_ERR("%s", pfmNumErrorMsg());
       /* Or, PFM_ERR("%s", pfmUtilGetErrorMsg()); */
       return RC_ERR;
    }
    
    if(pfmNumCmpAbs(a, b) < 0) {
       PFM_DBG("The absolute value of a is less than pi.");
    }

14. pfmNumIsInteger

Checks whether the input value is an integer.

  • Prototype

    pfmNumIsInteger(PfmNumber x);
  • Parameters

    Parameter Description

    x (input)

    PfmNumber value.

  • Return values

    Return Value Description

    TRUE

    The input value is an integer.

    FALSE

    The input value is not an integer.

  • Example

    PfmNumber   a;
    if(pfmNumIsInteger(a)) {
       PFM_DBG("a is an integer.");
    }

15. pfmNumCmpLong

Compares a PfmNumber value and a Long value.

  • Prototype

    long pfmNumCmpLong(PfmNumber x, long y);
  • Parameters

    Parameter Description

    x (input)

    PfmNumber value.

    y (input)

    Long value.

  • Return values

    Return Value Description

    0

    Means that x == y.

    Positive value

    Means that x > y.

    Negative value

    Means that x < y.

  • Example

    PfmNumber     a;
    long          b;
    
    if(pfmNumCmpLong(a, b) < 0) {
       PFM_DBG("a is less than b.");
       return RC_NRM;
    }

16. pfmNumCmpStr

Compares a PfmNumber value and a Char string.

  • Prototype

    long pfmNumCmpStr(PfmNumber x, char *str);
  • Parameters

    Parameter Description

    x (input)

    PfmNumber value.

    *str (input)

    Number value converted from a string.

  • Return values

    Return Value Description

    0

    Means that x == str.

    Positive value

    Means that x > str.

    Negative value

    Means that x < str.

  • Example

    PfmNumber     x;
    char          str[]  =  "333";
    
    rc = pfmNumGetFromLong(&x, 222);
    if(rc != RC_NRM) {
       PFM_ERR("%s", pfmNumErrorMsg());
       /* Or, PFM_ERR("%s", pfmUtilGetErrorMsg()); */
       return RC_ERR;
    }
    
    if(pfmNumCmpStr(x, str) < 0) {
       PFM_DBG("x is less than str.");
       return RC_NRM;
    }

17. pfmNumCmpStrn

Compares a PfmNumber value and a Char string with a given length.

  • Prototype

    long pfmNumCmpStrn(PfmNumber x, char *str, long len);
  • Parameters

    Parameter Description

    x (input)

    PfmNumber value.

    *str (input)

    Number value converted from a Char string.

    len (input)

    Length of str.

  • Return values

    Return Value Description

    0

    Means that x == str.

    Positive value

    Means that x > str.

    Negative value

    Means that x < str.

  • Example

    PfmNumber     x;
    char       str[]  =  "333";
    
    rc = pfmNumGetFromLong(&x, 222);
    if(rc != RC_NRM) {
       PFM_ERR("%s", pfmNumErrorMsg());
       /* Or, PFM_ERR("%s", pfmUtilGetErrorMsg()); */
       return RC_ERR;
    }
    
    if(pfmNumCmpStrn(x, str, strlen(str)) < 0) {
       PFM_DBG("x is less than y.");
       return RC_NRM;
    }

18. pfmNumNegate

Gets a negative value of a PfmNumber value (v = -x).

  • Prototype

    long pfmNumNegate(PfmNumber *v, PfmNumber x);
  • Parameters

    Parameter Description

    *v (output)

    Result value.

    x (input)

    PfmNumber value.

  • Return values

    Returns RC_NRM.

  • Example

    rc = pfmNumNegate(&x, x);
    if(rc != RC_NRM) {
       PFM_ERR("%s", pfmNumErrorMsg());
       /* Or, PFM_ERR("%s", pfmUtilGetErrorMsg()); */
       return RC_ERR;
    }
    /* x = -x */

19. pfmNumAbs

Gets an absolute value of a PfmNumber value (v = |x|).

  • Prototype

    long pfmNumAbs(PfmNumber *v, PfmNumber x);
  • Parameters

    Parameter Description

    *v (output)

    Result value.

    x (input)

    PfmNumber value.

  • Return values

    Return Value Description

    RC_NRM

    This API is executed successfully.

    RC_ERR

    This API is not executed successfully.

  • Example

    rc = pfmNumAbs(&a, a);
    if(rc != RC_NRM) {
       PFM_ERR("%s", pfmNumErrorMsg());
       /* Or, PFM_ERR("%s", pfmUtilGetErrorMsg()); */
       return RC_ERR;
    }
    /* a = |a| */

20. pfmNumAdd

Adds two PfmNumber values (v = x + y).

  • Prototype

    long pfmNumAdd(PfmNumber *v, PfmNumber x, PfmNumber y);
  • Parameters

    Parameter Description

    *v (output)

    Result value.

    x (input)

    First PfmNumber value.

    y (input)

    Second PfmNumber value.

  • Return values

    Return Value Description

    RC_NRM

    This API is executed successfully.

    RC_ERR

    This API is not executed successfully.

  • Example

    rc = pfmNumAdd(&a, b, c);
    if(rc != RC_NRM) {
       PFM_ERR("%s", pfmNumErrorMsg());
       /* Or, PFM_ERR("%s", pfmUtilGetErrorMsg()); */
       return RC_ERR;
    }
    /* a = b + c */

21. pfmNumSub

Subtracts the second PfmNumber value from the first PfmNumber value (v = x – y).

  • Prototype

    long pfmNumSub(PfmNumber *v, PfmNumber x, PfmNumber y);
  • Parameters

    Parameter Description

    *v (output)

    Result value.

    x (input)

    First PfmNumber value.

    y (input)

    Second PfmNumber value.

  • Return values

    Return Value Description

    RC_NRM

    This API is executed successfully.

    RC_ERR

    This API is not executed successfully.

  • Example

    rc = pfmNumSub(&a, b, c);
    if(rc != RC_NRM) {
       PFM_ERR("%s", pfmNumErrorMsg());
       /* Or, PFM_ERR("%s", pfmUtilGetErrorMsg()); */
       return RC_ERR;
    }
    /* a = b - c */

22. pfmNumMul

Multiplies two PfmNumber values (v = x * y).

  • Prototype

    long pfmNumMul(PfmNumber *v, PfmNumber x, PfmNumber y);
  • Parameters

    Parameter Description

    *v (output)

    Result value.

    x (input)

    First PfmNumber value.

    y (input)

    Second PfmNumber value.

  • Return values

    Return Value Description

    RC_NRM

    This API is executed successfully.

    RC_ERR

    This API is not executed successfully.

  • Example

    rc = pfmNumMul(&a, b, c);
    if(rc != RC_NRM) {
       PFM_ERR("%s", pfmNumErrorMsg());
       /* Or, PFM_ERR("%s", pfmUtilGetErrorMsg()); */
       return RC_ERR;
    }
    /* a = b * c */

23. pfmNumDiv

Divides the first PfmNumber value by the second PfmNumber value (v = x / y).

  • Prototype

    long pfmNumDiv(PfmNumber *v, PfmNumber x, PfmNumber y);
  • Parameters

    Parameter Description

    *v (output)

    Result value.

    x (input)

    First PfmNumber value.

    y (input)

    Second PfmNumber value.

  • Return values

    Return Value Description

    RC_NRM

    This API is executed successfully.

    RC_ERR

    This API is not executed successfully.

  • Example

    rc = pfmNumDiv(&a, b, c);
    if(rc != RC_NRM) {
       PFM_ERR("%s", pfmNumErrorMsg());
       /* Or, PFM_ERR("%s", pfmUtilGetErrorMsg()); */
       return RC_ERR;
    }
    /* a = b / c */

24. pfmNumIntDiv

Divides the first PfmNumber value by the second PfmNumber value and then converts the result value to an integer (v = x / y, where v is an integer).

  • Prototype

    long pfmNumIntDiv(PfmNumber *v, PfmNumber x, PfmNumber y);
  • Parameters

    Parameter Description

    *v (output)

    Result value.

    x (input)

    First PfmNumber value.

    y (input)

    Second PfmNumber value.

  • Return values

    Return Value Description

    RC_NRM

    This API is executed successfully.

    RC_ERR

    This API is not executed successfully.

  • Example

    PfmNumber     a, b;
    
    rc = pfmNumGetFromLong(&a, 10);
    if(rc != RC_NRM) {
       PFM_ERR("%s", pfmNumErrorMsg());
       /* Or, PFM_ERR("%s", pfmUtilGetErrorMsg()); */
       return RC_ERR;
    }
    
    rc = pfmNumGetFromLong(&b, 3);
    if(rc != RC_NRM) {
       PFM_ERR("%s", pfmNumErrorMsg());
       /* Or, PFM_ERR("%s", pfmUtilGetErrorMsg()); */
       return RC_ERR;
    }
    
    rc = pfmNumIntDiv(&a, a, b);
    if(rc != RC_NRM) {
       PFM_ERR("%s", pfmNumErrorMsg());
       /* Or, PFM_ERR("%s", pfmUtilGetErrorMsg()); */
       return RC_ERR;
    }
    /* a == (int)(a / b) = (int)(10 / 3) = 3, not 3.333333 */

25. pfmNumMod

Finds the remainder of dividing the first PfmNumber value by the second PfmNumber value (v = x – (y * n)).

  • Prototype

    long pfmNumMod(PfmNumber *v, PfmNumber x, PfmNumber y);
  • Parameters

    Parameter Description

    *v (output)

    Result value.

    x (input)

    First PfmNumber value.

    y (input)

    Second PfmNumber value.

  • Return values

    Return Value Description

    RC_NRM

    This API is executed successfully.

    RC_ERR

    This API is not executed successfully.

  • Example

    PfmNumber     a, b;
    
    rc = pfmNumGetFromStr(&a, "11.000001");
    if(rc != RC_NRM) {
       PFM_ERR("%s", pfmNumErrorMsg());
       /* Or, PFM_ERR("%s", pfmUtilGetErrorMsg()); */
       return RC_ERR;
    }
    
    rc = pfmNumGetFromStr(&b, "4.0000001");
    if(rc != RC_NRM) {
       PFM_ERR("%s", pfmNumErrorMsg());
       /* Or, PFM_ERR("%s", pfmUtilGetErrorMsg()); */
       return RC_ERR;
    }
    
    rc = pfmNumMod(&a, a, b);
    if(rc != RC_NRM) {
       PFM_ERR("%s", pfmNumErrorMsg());
       /* Or, PFM_ERR("%s", pfmUtilGetErrorMsg()); */
       return RC_ERR;
    }
    /* a == a % b = 11.000001 – 2 * 4.0000001 = 3.0000008 */

26. pfmNumModDiv

Finds the quotient and remainder of dividing the first PfmNumber value by the second PfmNumber value.

  • Prototype

    long pfmNumModDiv(PfmNumber *v, PfmNumber x, PfmNumber *mod, PfmNumber y);
  • Parameters

    Parameter Description

    *v (output)

    Quotient of the division.

    *mod (output)

    Remainder of the division.

    x (input)

    First PfmNumber value.

    y (input)

    Second PfmNumber value.

  • Return values

    Return Value Description

    RC_NRM

    This API is executed successfully.

    RC_ERR

    This API is not executed successfully.

  • Example

    PfmNumber     x, y;
    PfmNumber     a, b;
    
    rc = pfmNumGetFromStr(&a, "11.1");
    if(rc != RC_NRM) {
       PFM_ERR("%s", pfmNumErrorMsg());
       /* Or, PFM_ERR("%s", pfmUtilGetErrorMsg()); */
       return RC_ERR;
    }
    
    rc = pfmNumGetFromStr(&b, "4.01");
    if(rc != RC_NRM) {
       PFM_ERR("%s", pfmNumErrorMsg());
       /* Or, PFM_ERR("%s", pfmUtilGetErrorMsg()); */
       return RC_ERR;
    }
    
    rc = pfmNumModDiv(&x, &y, a, b);
    if(rc != RC_NRM) {
       PFM_ERR("%s", pfmNumErrorMsg());
       /* Or, PFM_ERR("%s", pfmUtilGetErrorMsg()); */
       return RC_ERR;
    }
    /* x == 2, y == 3.08 */

27. pfmNumTruncAt

Rounds down a PfmNumber value to a given position.

  • Prototype

    long pfmNumTruncAt(PfmNumber *v, PfmNumber x, long pos);
  • Parameters

    Parameter Description

    *v (output)

    Result value.

    x (input)

    PfmNumber value.

    pos (input)

    Rounding down position.

  • Return values

    Return Value Description

    RC_NRM

    This API is executed successfully.

    RC_ERR

    This API is not executed successfully.

  • Example

    PfmNumber     x;
    PfmNumber     y;
    
    pfmNumGetFromStr(&x, "123.1561");
    rc = pfmNumTruncAt(&y, x, 2);
    /* x == 123.15*/
    
    pfmNumGetFromStr(&x, "123.1561");
    rc = pfmNumTruncAt(&y, x, -2);
    /* x == 100 */
    
    if(rc != RC_NRM) {
       PFM_ERR("%s", pfmNumErrorMsg());
       /* Or, PFM_ERR("%s", pfmUtilGetErrorMsg()); */
       return RC_ERR;
    }

28. pfmNumRoundAt

Rounds off a PfmNumber value to a given position of decimal places.

  • Prototype

    long pfmNumRoundAt(PfmNumber *v, PfmNumber x, long pos);
  • Parameters

    Parameter Description

    *v (output)

    Result value.

    x (input)

    PfmNumber value.

    pos (input)

    Rounding position.

  • Return values

    Return Value Description

    RC_NRM

    This API is executed successfully.

    RC_ERR

    This API is not executed successfully.

  • Example

    PfmNumber     x;
    PfmNumber     y;
    
    pfmNumGetFromStr(&x, "123.1561");
    rc = pfmNumRoundAt(&y, x, 2);
    /* x == 123.16 */
    
    pfmNumGetFromStr(&x, "123.1561");
    rc = pfmNumRoundAt(&y, x, -2);
    /* x == 100 */
    
    if(rc != RC_NRM) {
       PFM_ERR("%s", pfmNumErrorMsg());
       /* Or, PFM_ERR("%s", pfmUtilGetErrorMsg()); */
       return RC_ERR;
    }

29. pfmNumTrunc

Rounds down the fraction part of a PfmNumber value.

  • Prototype

    long pfmNumTrunc(PfmNumber *v, PfmNumber x);
  • Parameters

    Parameter Description

    *v (output)

    Result value.

    x (input)

    PfmNumber value.

  • Return values

    Return Value Description

    RC_NRM

    This API is executed successfully.

    RC_ERR

    This API is not executed successfully.

  • Example

    PfmNumber     a, b;
    
    rc = pfmNumGetFromStr(&a, "-12.345");
    if(rc != RC_NRM) {
       PFM_ERR("%s", pfmNumErrorMsg());
       /* Or, PFM_ERR("%s", pfmUtilGetErrorMsg()); */
       return RC_ERR;
    }
    
    rc = pfmNumTrunc(&b, a);
    if(rc != RC_NRM) {
       PFM_ERR("%s", pfmNumErrorMsg());
       /* Or, PFM_ERR("%s", pfmUtilGetErrorMsg()); */
       return RC_ERR;
    }
    /* b == -12 */

30. pfmNumRound

Rounds off a PfmNumber value to one digit.

  • Prototype

    long pfmNumRound(PfmNumber *v, PfmNumber x);
  • Parameters

    Parameter Description

    *v (output)

    Result value.

    x (input)

    PfmNumber value.

  • Return values

    Return Value Description

    RC_NRM

    This API is executed successfully.

    RC_ERR

    This API is not executed successfully.

  • Example

    rc = pfmNumGetFromStr(&a, "-12.4");
    if(rc != RC_NRM) {
       PFM_ERR("%s", pfmNumErrorMsg());
       /* Or, PFM_ERR("%s", pfmUtilGetErrorMsg()); */
       return RC_ERR;
    }
    rc = pfmNumRound(&a, a);
    if(rc != RC_NRM) {
       PFM_ERR("%s", pfmNumErrorMsg());
       /* Or, PFM_ERR("%s", pfmUtilGetErrorMsg()); */
       return RC_ERR;
    }
    /* a == -12 */
    
    rc = pfmNumGetFromStr(&a, "-12.7");
    if(rc != RC_NRM) {
       PFM_ERR("%s", pfmNumErrorMsg());
       /* Or, PFM_ERR("%s", pfmUtilGetErrorMsg()); */
       return RC_ERR;
    }
    rc = pfmNumRound(&a, a);
    if(rc != RC_NRM) {
       PFM_ERR("%s", pfmNumErrorMsg());
       /* Or, PFM_ERR("%s", pfmUtilGetErrorMsg()); */
       return RC_ERR;
    }
    /* a == -13 */

31. pfmNumSqr

Raises a PfmNumber value to a power (v = x2 ).

  • Prototype

    long pfmNumSqr(PfmNumber *v, PfmNumber x);
  • Parameters

    Parameter Description

    *v (output)

    Result value.

    x (input)

    PfmNumber value.

  • Return values

    Return Value Description

    RC_NRM

    This API is executed successfully.

    RC_ERR

    This API is not executed successfully.

  • Example

    PfmNumber     a;
    
    rc = pfmNumGetFromLong(&a, 4);
    if(rc != RC_NRM) {
       PFM_ERR("%s", pfmNumErrorMsg());
       /* Or, PFM_ERR("%s", pfmUtilGetErrorMsg()); */
       return RC_ERR;
    }
    
    rc = pfmNumSqr(&a, a);
    if(rc != RC_NRM) {
       PFM_ERR("%s", pfmNumErrorMsg());
       /* Or, PFM_ERR("%s", pfmUtilGetErrorMsg()); */
       return RC_ERR;
    }
    /* a == 16 */

32. pfmNumPower

Raises the first PfmNumber value to the power of the second PfmNumber value (v = xy).

  • Prototype

    long pfmNumPower(PfmNumber *v, PfmNumber x, PfmNumber y);
  • Parameters

    Parameter Description

    *v (output)

    Result value.

    x (input)

    First PfmNumber value.

    y (input)

    Second PfmNumber value.

  • Return values

    Return Value Description

    RC_NRM

    This API is executed successfully.

    RC_ERR

    This API is not executed successfully.

  • Example

    PfmNumber     a, b;
    
    rc = pfmNumGetFromLong(&a, 4);
    if(rc != RC_NRM) {
       PFM_ERR("%s", pfmNumErrorMsg());
       /* Or, PFM_ERR("%s", pfmUtilGetErrorMsg()); */
       return RC_ERR;
    }
    
    rc = pfmNumGetFromLong (&b,3);
    if(rc != RC_NRM) {
       PFM_ERR("%s", pfmNumErrorMsg());
       /* Or, PFM_ERR("%s", pfmUtilGetErrorMsg()); */
       return RC_ERR;
    }
    
    rc = pfmNumPower(&a, a, b);
    if(rc != RC_NRM) {
       PFM_ERR("%s", pfmNumErrorMsg());
       /* Or, PFM_ERR("%s", pfmUtilGetErrorMsg()); */
       return RC_ERR;
    }
    /* a == 4^3 = 64 */

33. pfmNumInc

Adds two PfmNumber values and then assigns the result to the first PfmNumber value (x = x + y).

  • Prototype

    long pfmNumInc(PfmNumber *x, PfmNumber y);
  • Parameters

    Parameter Description

    *x (input/output)

    Result PfmNumber value.

    y (input)

    PfmNumber value.

  • Return values

    Return Value Description

    RC_NRM

    This API is executed successfully.

    RC_ERR

    This API is not executed successfully.

  • Example

    rc = pfmNumInc(&a, b);
    if(rc != RC_NRM) {
       PFM_ERR("%s", pfmNumErrorMsg());
       /* Or, PFM_ERR("%s", pfmUtilGetErrorMsg()); */
       return RC_ERR;
    }
    /* a = a + b*/

34. pfmNumDec

Subtracts the second PfmNumber value from the first PfmNumber value and then assigns the result to the first PfmNumber value (x = x - y).

  • Prototype

    long pfmNumDec(PfmNumber *x, PfmNumber y);
  • Parameters

    Parameter Description

    *x (input/output)

    Result PfmNumber value.

    y (input)

    PfmNumber value.

  • Return values

    Return Value Description

    RC_NRM

    This API is executed successfully.

    RC_ERR

    This API is not executed successfully.

  • Example

    rc = pfmNumDec(&a, b);
    if(rc != RC_NRM) {
       PFM_ERR("%s", pfmNumErrorMsg());
       /* Or, PFM_ERR("%s", pfmUtilGetErrorMsg()); */
       return RC_ERR;
    }
    /* a = a - b*/

35. pfmNumAddStr

Converts a string to a number and then adds it to a PfmNumber value (v = x + str).

  • Prototype

    long pfmNumAddStr(PfmNumber *v, PfmNumber x, char *str);
  • Parameters

    Parameter Description

    *v (output)

    Result value.

    x (input)

    PfmNumber value.

    *str (input)

    String to convert to a number.

  • Return values

    Return Value Description

    RC_NRM

    This API is executed successfully.

    RC_ERR

    This API is not executed successfully.

  • Example

    PfmNumber     v, x;
    char     str[] = "11";
    
    PfmNumGetFromLong(&x, 30);
    if(rc != RC_NRM) {
       PFM_ERR("%s", pfmNumErrorMsg());
       /* Or, PFM_ERR("%s", pfmUtilGetErrorMsg()); */
       return RC_ERR;
    }
    
    rc = pfmNumAddStr(&v, x, str);
    if(rc != RC_NRM) {
       PFM_ERR("%s", pfmNumErrorMsg());
       /* Or, PFM_ERR("%s", pfmUtilGetErrorMsg()); */
       return RC_ERR;
    }
    /* v = 41 */

36. pfmNumSubStr

Converts a string to a number and then subtract it from a PfmNumber value (v = x - str).

  • Prototype

    long pfmNumSubStr(PfmNumber *v, PfmNumber x, char *str);
  • Parameters

    Parameter Description

    *v (output)

    Result value.

    x (input)

    PfmNumber value.

    *str (input)

    String to convert to a number.

  • Return values

    Return Value Description

    RC_NRM

    This API is executed successfully.

    RC_ERR

    This API is not executed successfully.

  • Example

    PfmNumber     v, x;
    char   str[] = "11";
    
    PfmNumGetFromLong(&x, 30);
    if(rc != RC_NRM) {
       PFM_ERR("%s", pfmNumErrorMsg());
       /* Or, PFM_ERR("%s", pfmUtilGetErrorMsg()); */
       return RC_ERR;
    }
    
    rc = pfmNumSubStr(&v, x, str);
    if(rc != RC_NRM) {
       PFM_ERR("%s", pfmNumErrorMsg());
       /* Or, PFM_ERR("%s", pfmUtilGetErrorMsg()); */
       return RC_ERR;
    }
    /* v = 19 */

37. pfmNumMulStr

Converts a string to a number and then multiples it and a PfmNumber value (v = x * str).

  • Prototype

    long pfmNumMulStr(PfmNumber *v, PfmNumber x, char *str);
  • Parameters

    Parameter Description

    *v (output)

    Result value.

    x (input)

    PfmNumber value.

    *str (input)

    String to convert to a number.

  • Return values

    Return Value Description

    RC_NRM

    This API is executed successfully.

    RC_ERR

    This API is not executed successfully.

  • Example

    PfmNumber     v, x;
    char          str[] = "11";
    
    PfmNumGetFromLong(&x, 30);
    if(rc != RC_NRM) {
       PFM_ERR("%s", pfmNumErrorMsg());
       /* Or, PFM_ERR("%s", pfmUtilGetErrorMsg()); */
       return RC_ERR;
    }
    
    rc = pfmNumMulStr(&v, x, str);
    if(rc != RC_NRM) {
       PFM_ERR("%s", pfmNumErrorMsg());
       /* Or, PFM_ERR("%s", pfmUtilGetErrorMsg()); */
       return RC_ERR;
    }
    /* v = 330 */

38. pfmNumDivString

Converts a string to a number and then divides a PfmNumber value by it (v = x / str).

  • Prototype

    long pfmNumDivString(PfmNumber *v, PfmNumber x, char *str);
  • Parameters

    Parameter Description

    *v (output)

    Result value.

    x (input)

    PfmNumber value.

    *str (input)

    String to convert to a number.

  • Return values

    Return Value Description

    RC_NRM

    This API is executed successfully.

    RC_ERR

    This API is not executed successfully.

  • Example

    PfmNumber     v, x;
    char          str[] = "11";
    
    PfmNumGetFromLong(&x, 30);
    if(rc != RC_NRM) {
       PFM_ERR("%s", pfmNumErrorMsg());
       /* Or, PFM_ERR("%s", pfmUtilGetErrorMsg()); */
       return RC_ERR;
    }
    
    rc = pfmNumDivString(&v, x, str);
    if(rc != RC_NRM) {
       PFM_ERR("%s", pfmNumErrorMsg());
       /* Or, PFM_ERR("%s", pfmUtilGetErrorMsg()); */
       return RC_ERR;
    }
    /* v = 30 / 11 == 2.72727272727272727272727272727 */

39. pfmNumAddStrn

Converts a fixed-size string to a number and then adds it to a PfmNumber value (v = x + str).

  • Prototype

    long pfmNumAddStrn(PfmNumber *v, PfmNumber x, char *str, long len);
  • Parameters

    Parameter Description

    *v (output)

    Result value.

    x (input)

    PfmNumber value.

    *str (input)

    String to convert to a number.

    len

    Length of the input string.

  • Return values

    Return Value Description

    RC_NRM

    This API is executed successfully.

    RC_ERR

    This API is not executed successfully.

  • Example

    PfmNumber     v, x;
    char      str[] = "11";
    
    PfmNumGetFromLong(&x, 30);
    if(rc != RC_NRM) {
       PFM_ERR("%s", pfmNumErrorMsg());
       /* Or, PFM_ERR("%s", pfmUtilGetErrorMsg()); */
       return RC_ERR;
    }
    
    rc = pfmNumAddStrn(&v, x, str, strlen(str));
    if(rc != RC_NRM) {
       PFM_ERR("%s", pfmNumErrorMsg());
       /* Or, PFM_ERR("%s", pfmUtilGetErrorMsg()); */
       return RC_ERR;
    }
    /* v = 41 */

40. pfmNumSubStrn

Converts a fixed-length string to a number and then subtract it from a PfmNumber value (v = x - str).

  • Prototype

    long pfmNumSubStrn(PfmNumber *v, PfmNumber x, char *str, long len);
  • Parameters

    Parameter Description

    *v (output)

    Result value.

    x (input)

    PfmNumber value.

    *str (input)

    String to convert to a number.

    len

    Length of the input string.

  • Return values

    Return Value Description

    RC_NRM

    This API is executed successfully.

    RC_ERR

    This API is not executed successfully.

  • Example

    PfmNumber     v, x;
    char      str[] = "11";
    
    PfmNumGetFromLong(&x, 30);
    if(rc != RC_NRM) {
       PFM_ERR("%s", pfmNumErrorMsg());
       /* Or, PFM_ERR("%s", pfmUtilGetErrorMsg()); */
       return RC_ERR;
    }
    
    rc = pfmNumSubStrn(&v, x, str, strlen(str));
    if(rc != RC_NRM) {
       PFM_ERR("%s", pfmNumErrorMsg());
       /* Or, PFM_ERR("%s", pfmUtilGetErrorMsg()); */
       return RC_ERR;
    }
    /* v = 19 */

41. pfmNumMulStrn

Converts a fixed-length string to a number and then multiples it and a PfmNumber value (v = x * str).

  • Prototype

    long pfmNumMulStrn(PfmNumber *v, PfmNumber x, char *str, long len);
  • Parameters

    Parameter Description

    *v (output)

    Result value.

    x (input)

    PfmNumber value.

    *str (input)

    String to convert to a number.

    len

    Length of the input string.

  • Return values

    Return Value Description

    RC_NRM

    This API is executed successfully.

    RC_ERR

    This API is not executed successfully.

  • Example

    PfmNumber     v, x;
    char         str[] = "11";
    
    PfmNumGetFromLong(&x, 30);
    if(rc != RC_NRM) {
       PFM_ERR("%s", pfmNumErrorMsg());
       /* Or, PFM_ERR("%s", pfmUtilGetErrorMsg()); */
       return RC_ERR;
    }
    
    rc = pfmNumMulStrn(&v, x, str, strlen(str));
    if(rc != RC_NRM) {
       PFM_ERR("%s", pfmNumErrorMsg());
       /* Or, PFM_ERR("%s", pfmUtilGetErrorMsg()); */
       return RC_ERR;
    }
    /* v = 330 */

42. pfmNumDivStrn

Converts a fixed-length string to a number and then divides a PfmNumber value by it (v = x / str).

  • Prototype

    long pfmNumDivStrn(PfmNumber *v, PfmNumber x, char *str, long len);
  • Parameters

    Parameter Description

    *v (output)

    Result value.

    x (input)

    PfmNumber value.

    *str (input)

    String to convert to a number.

    len

    Length of the input string.

  • Return values

    Return Value Description

    RC_NRM

    This API is executed successfully.

    RC_ERR

    This API is not executed successfully.

  • Example

    PfmNumber     v, x;
    char         str[] = "11";
    
    PfmNumGetFromLong(&x, 30);
    if(rc != RC_NRM) {
       PFM_ERR("%s", pfmNumErrorMsg());
       /* Or, PFM_ERR("%s", pfmUtilGetErrorMsg()); */
       return RC_ERR;
    }
    
    rc = pfmNumDivStrn(&v, x, str, strlen(str));
    if(rc != RC_NRM) {
       PFM_ERR("%s", pfmNumErrorMsg());
       /* Or, PFM_ERR("%s", pfmUtilGetErrorMsg()); */
       return RC_ERR;
    }
    /* v = 30 / 11 == 2.72727272727272727272727272727 */

43. pfmNumAddLong

Adds a PfmNumber value and a Long value (v = x + y, where y is a Long value).

  • Prototype

    long pfmNumAddLong(PfmNumber *v, PfmNumber x, long len);
  • Parameters

    Parameter Description

    *v (output)

    Result value.

    x (input)

    PfmNumber value.

    len (input)

    Long value.

  • Return values

    Return Value Description

    RC_NRM

    This API is executed successfully.

    RC_ERR

    This API is not executed successfully.

  • Example

    PfmNumber     a;
    long          b;
    
    rc = pfmNumAddLong(&a, a, b);
    if(rc != RC_NRM) {
       PFM_ERR("%s", pfmNumErrorMsg());
       /* Or, PFM_ERR("%s", pfmUtilGetErrorMsg()); */
       return RC_ERR;
    }

44. pfmNumSubLong

Subtracts a Long value from a PfmNumber value (v = x – y, where y is a Long value).

  • Prototype

    long pfmNumSubLong(PfmNumber *v, PfmNumber x, long y);
  • Parameters

    Parameter Description

    *v (output)

    Result value.

    x (input)

    PfmNumber value.

    y (input)

    Long value.

  • Return values

    Return Value Description

    RC_NRM

    This API is executed successfully.

    RC_ERR

    This API is not executed successfully.

  • Example

    PfmNumber     a;
    long          b;
    
    rc = pfmNumSubLong(&a, a, b);
    if(rc != RC_NRM) {
       PFM_ERR("%s", pfmNumErrorMsg());
       /* Or, PFM_ERR("%s", pfmUtilGetErrorMsg()); */
       return RC_ERR;
    }
    rc = pfmNumSubLong(&a, a, 4178);
    if(rc != RC_NRM) {
       PFM_ERR("%s", pfmNumErrorMsg());
       /* Or, PFM_ERR("%s", pfmUtilGetErrorMsg()); */
       return RC_ERR;
    }

45. pfmNumMulLong

Multiplies a PfmNumber value and a Long value (v = x * y, where y is a Long value).

  • Prototype

    long pfmNumMulLong(PfmNumber *v, PfmNumber x, long y);
  • Parameters

    Parameter Description

    *v (output)

    Result value.

    x (input)

    PfmNumber value.

    y (input)

    Long value.

  • Return values

    Return Value Description

    RC_NRM

    This API is executed successfully.

    RC_ERR

    This API is not executed successfully.

  • Example

    PfmNumber     a, b;
    long          n;
    
    rc = pfmNumMulLong(&a, b, n);
    if(rc != RC_NRM) {
       PFM_ERR("%s", pfmNumErrorMsg());
       /* Or, PFM_ERR("%s", pfmUtilGetErrorMsg()); */
       return RC_ERR;
    }
    /* a == b * n */

46. pfmNumDivLong

Divides a PfmNumber value by a Long value (v = x / y, where y is a Long value).

  • Prototype

    long pfmNumDivLong(PfmNumber *v, PfmNumber x, long y);
  • Parameters

    Parameter Description

    *v (output)

    Result value.

    x (input)

    PfmNumber value.

    y (input)

    Long value.

  • Return values

    Return Value Description

    RC_NRM

    This API is executed successfully.

    RC_ERR

    This API is not executed successfully.

  • Example

    PfmNumber     a, b;
    long          n;
    rc = pfmNumDivLong(&a, b, n);
    if(rc != RC_NRM) {
       PFM_ERR("%s", pfmNumErrorMsg());
       /* Or, PFM_ERR("%s", pfmUtilGetErrorMsg()); */
       return RC_ERR;
    }
    /* a == b / n */

47. pfmNumModDivLong

Finds the quotient and remainder of dividing the PfmNumber value by a Long value.

  • Prototype

    long pfmNumModDivLong(PfmNumber *v, PfmNumber *mod, PfmNumber x, long y);
  • Parameters

    Parameter Description

    *v (output)

    Quotient of the division.

    *mod (output)

    Remainder of the division.

    x (input)

    PfmNumber value.

    y (input)

    Long value.

  • Return values

    Return Value Description

    RC_NRM

    This API is executed successfully.

    RC_ERR

    This API is not executed successfully.

  • Example

    PfmNumber     q, r, a;
    long          b;
    
    rc = pfmNumModDivLong(&q, &r, a, b);
    if(rc != RC_NRM) {
       PFM_ERR("%s", pfmNumErrorMsg());
       /* Or, PFM_ERR("%s", pfmUtilGetErrorMsg()); */
       return RC_ERR;
    }
    /* a == b * q + r */

48. pfmNumAddN

Adds up an input value as many times as an input count (v = x + x +…).

  • Prototype

    long pfmNumAddN(long cnt, PfmNumber *v, PfmNumber x, …);
  • Parameters

    Parameter Description

    cnt (input)

    Number of operands.

    *v (output)

    Result value.

    x (input)

    First operand.

    … (input)

    Second and subsequent operands.

  • Return values

    Return Value Description

    RC_NRM

    This API is executed successfully.

    RC_ERR

    This API is not executed successfully.

  • Example

    PfmNumber     a, n;
    
    a = n = PFMNUM_ZERO;
    
    rc = pfmNumAddN(3, &n, PFMNUM_ONE, PFMNUM_ONE, PFMNUM_ONE);
    if(rc != RC_NRM) {
       PFM_ERR("%s", pfmNumErrorMsg());
       /* Or, PFM_ERR("%s", pfmUtilGetErrorMsg()); */
       return RC_ERR;
    }
    /* n == 1+ 1+ 1 = 3 */

    The folloiwng describes each constant used in the previous example.

    Constant Description

    PFMNUM_ZERO

    PfmNumber constant indicating 0.

    PFMNUM_ONE

    PfmNumber constant indicating 1.

49. pfmNumMulN

Multiplies an input value as many times as an input count (v = x * x *…).

  • Prototype

    long pfmNumMulN(long cnt, PfmNumber *v, PfmNumber x, …);
  • Parameters

    Parameter Description

    cnt (input)

    Number of operands.

    *v (output)

    Result value.

    x (input)

    First operand.

    … (input)

    Second and subsequent operands.

  • Return values

    Return Value Description

    RC_NRM

    This API is executed successfully.

    RC_ERR

    This API is not executed successfully.

  • Example

    PfmNumber     a, b, c, d, n;
    
    rc = pfmNumGetFromLong(&a, 2);
    if(rc != RC_NRM) {
       PFM_ERR("%s", pfmNumErrorMsg());
       /* Or, PFM_ERR("%s", pfmUtilGetErrorMsg()); */
       return RC_ERR;
    }
    rc = pfmNumGetFromLong(&b, 3);
    if(rc != RC_NRM) {
       PFM_ERR("%s", pfmNumErrorMsg());
       /* Or, PFM_ERR("%s", pfmUtilGetErrorMsg()); */
       return RC_ERR;
    }
    rc = p pfmNumGetFromLong (&c, 4);
    if(rc != RC_NRM) {
       PFM_ERR("%s", pfmNumErrorMsg());
       /* Or, PFM_ERR("%s", pfmUtilGetErrorMsg()); */
       return RC_ERR;
    }
    rc = pfmNumGetFromLong (&d, 5);
    if(rc != RC_NRM) {
       PFM_ERR("%s", pfmNumErrorMsg());
       /* Or, PFM_ERR("%s", pfmUtilGetErrorMsg()); */
       return RC_ERR;
    }
    rc = pfmNumMulN(4, &n, a, b, c, d);
    if(rc != RC_NRM) {
       PFM_ERR("%s", pfmNumErrorMsg());
       /* Or, PFM_ERR("%s", pfmUtilGetErrorMsg()); */
       return RC_ERR;
    }
    /* n == a * b * c * d = 2 * 3 * 4 * 5 = 120 */

50. pfmNumPowLong

Multiplies an input value y times (v = xy).

  • Prototype

    long pfmNumPowLong(PfmNumber *v, PfmNumber x, long y);
  • Parameters

    Parameter Description

    *v (output)

    Result value.

    x (input)

    PfmNumber value.

    y (input)

    Long value.

  • Return values

    Return Value Description

    RC_NRM

    This API is executed successfully.

    RC_ERR

    This API is not executed successfully.

  • Example

    PfmNumber     v, x;
    
    PfmNumGetFromStr(&x, "2");
    if(rc != RC_NRM) {
       PFM_ERR("%s", pfmNumErrorMsg());
       /* Or, PFM_ERR("%s", pfmUtilGetErrorMsg()); */
       return RC_ERR;
    }
    rc = pfmNumPowLong(&v, x, 10);    /* v = 2^10 */
    if(rc != RC_NRM) {
       PFM_ERR("%s", pfmNumErrorMsg());
       /* Or, PFM_ERR("%s", pfmUtilGetErrorMsg()); */
       return RC_ERR;
    }
    /* v = 1024 */

51. pfmNumRound

Rounds off a PfmNumber value to a given position of decimal places and then assigns the result value to the first parameter (v).

  • Prototype

    long pfmNumRound(PfmNumber *v, PfmNumber x, long pos);
  • Parameters

    Parameter Description

    *v (output)

    Result value.

    x (input)

    PfmNumber value.

    pos (input)

    Rounding position after a decimal point.

  • Return values

    Return Value Description

    RC_NRM

    This API is executed successfully.

    RC_ERR

    This API is not executed successfully.

  • Example

    PfmNumber     v, x;
    
    rc = pfmNumGetFromStr(&x, "123.1561");
    if(rc != RC_NRM) {
       PFM_ERR("%s", pfmNumErrorMsg());
       /* Or, PFM_ERR("%s", pfmUtilGetErrorMsg()); */
       return RC_ERR;
    }
    
    /* v = 123.16 */
    rc = pfmNumRound(&v, x, 2);
    if(rc != RC_NRM) {
       PFM_ERR("%s", pfmNumErrorMsg());
       /* Or, PFM_ERR("%s", pfmUtilGetErrorMsg()); */
       return RC_ERR;
    }

52. pfmNumRoundUp

Rounds up a PfmNumber value to a given position of decimal places and then assigns the result value to the first parameter (v).

  • Prototype

    long pfmNumRoundUp(PfmNumber *v, PfmNumber x, long pos);
  • Parameters

    Parameter Description

    *v (output)

    Result value.

    x (input)

    PfmNumber value.

    pos (input)

    Rounding up position after a decimal point.

  • Return values

    Return Value Description

    RC_NRM

    This API is executed successfully.

    RC_ERR

    This API is not executed successfully.

  • Example

    PfmNumber     v, x;
    
    rc = pfmNumGetFromStr(&x, "123.1561");
    if(rc != RC_NRM) {
       PFM_ERR("%s", pfmNumErrorMsg());
       /* Or, PFM_ERR("%s", pfmUtilGetErrorMsg()); */
       return RC_ERR;
    }
    
    /* v1 = 123.157 */
    rc = pfmNumRoundUp(&v, x, 3);
    if(rc != RC_NRM) {
       PFM_ERR("%s", pfmNumErrorMsg());
       /* Or, PFM_ERR("%s", pfmUtilGetErrorMsg()); */
       return RC_ERR;
    }

53. pfmNumCalc

Calculates arithmetic operations and outputs the result as PfmNumber values.

  • Available operators

    Parentheses (duplication allowed), 4 arithmetic operations (+, -, *, /), power (^), mod (%), and constants

  • Prototype

    long pfmNumCalc(PfmNumber *num, char *frmt, …);
  • Parameters

    Parameter Description

    *num (output)

    Result value.

    *frmt (input)

    Data type expression.

    • Long type: %ld

    • Character type: %s

    • Number type: %n

    Data corresponding to the data type specified with *frmt.

  • Return values

    Return Value Description

    RC_NRM

    This API is executed successfully.

    RC_ERR

    This API is not executed successfully.

  • Example

    PfmNumber     num, a;
    long         b  =  2;
    
    rc = pfmNumGetFromStr(&a, "1");
    if(rc != RC_NRM) {
       PFM_ERR("%s", pfmNumErrorMsg());
       /* Or, PFM_ERR("%s", pfmUtilGetErrorMsg()); */
       return RC_ERR;
    }   rc = pfmNumCalc(&num, "(-1 + 5 * %n) / %ld - %s", a, b, "1");
    if(rc != RC_NRM) {
       PFM_ERR("%s", pfmNumErrorMsg());
       /* Or, PFM_ERR("%s", pfmUtilGetErrorMsg()); */
       return RC_ERR;
    } else {
       PRINT_PFMNUMBER(&num);
    }
    /* num = 1 */

54. pfmNumCalcLong

Calculates arithmetic operations and outputs the result as Long values.

  • Available operators

    Parentheses (duplication allowed), 4 arithmetic operations (+, -, *, /), power (^), mod (%), and constants

  • Prototype

    long pfmNumCalcLong(long *lval, char *frmt, …);
  • Parameters

    Parameter Description

    *lval (output)

    Result value.

    *frmt (input)

    Data type expression.

    • Long type: %ld

    • Character type: %s

    • Number type: %n

    Data corresponding to the data type specified with *frmt.

  • Return values

    Return Value Description

    RC_NRM

    This API is executed successfully.

    RC_ERR

    This API is not executed successfully.

  • Example

    PfmNumber    a;
    long         lval, b  =  2;
    
    rc = pfmNumGetFromStr(&a, "1");
    if(rc != RC_NRM) {
       PFM_ERR("%s", pfmNumErrorMsg());
       /* Or, PFM_ERR("%s", pfmUtilGetErrorMsg()); */
       return RC_ERR;
    }
    rc = pfmNumCalcLong(&lval, "(-1 + 5 * %n) / %ld - %s", a, b, "1");
    if(rc != RC_NRM){
       PFM_ERR("%s", pfmNumErrorMsg());
       /* Or, PFM_ERR("%s", pfmUtilGetErrorMsg()); */
       return RC_ERR;
    } else {
       PFM_DBG("lval = %ld", &lval);
    }
    /* lval = 1 */

55. pfmNumToCommaStrN

Converts a PfmNumber number to a string including commas.

  • Prototype

    long pfmNumToCommaStrN(char *str, PfmNumber x, long buf_size);
  • Parameters

    Parameter Description

    *str (output)

    Result string.

    x (input)

    PfmNumber value.

    buf_size

    Length of str.

  • Return values

    Return Value Description

    RC_NRM

    This API is executed successfully.

    RC_ERR

    This API is not executed successfully.

  • Example

    PfmNumber    a;
    char str[20]= {0,};
    
    rc = pfmNumGetFromStr(&a, "123456789.124");
    if(rc != RC_NRM) {
       PFM_ERR("%s", pfmNumErrorMsg());
       /* Or, PFM_ERR("%s", pfmUtilGetErrorMsg()); */
       return RC_ERR;
    }
    
    rc = pfmNumToCommaStrN(str, x, sizeof(str));
    if(rc != RC_NRM) {
       PFM_ERR("%s", pfmNumErrorMsg());
       /* Or, PFM_ERR("%s", pfmUtilGetErrorMsg()); */
       return RC_ERR;
    }
    /* str = 123,456,789.124 */

56. pfmNumToInFmtStrN

Converts a PfmNumber number to a string in a specific format.

  • Prototype

    long pfmNumToInFmtStrN(char *str, long buf_size, char *frmt,
    long right_align_flag, long lpad_zero_flag, PfmNumber x);
  • Parameters

    Parameter Description

    *str (output)

    Result string.

    buf_size (input)

    Length of str.

    *frmt (input)

    Format after the conversion.

    • '#': Assigns a digit if the digit exists. If not, this is ignored.

    • '0': Assigns a digit if the digit exists. If not, 0 is assigned.

    • Numbers: %n

    • '.' (point): decimal point.

    right_align_flag (input)

    How to align the result after the format conversion.

    • '0': Aligns left.

    • '1': Aligns right.

    lpad_zero_flag (input)

    How to treat left spaces when the right alignment is used after the format conversion.

    • '0': Treats a space as a blank.

    • '1': Treats a space as 0.

    x (input)

    PfmNumber value.

  • Return values

    Return Value Description

    RC_NRM

    This API is executed successfully.

    RC_ERR

    This API is not executed successfully.

  • Example

    PfmNumber    a;
    char str[100]= {0,};
    rc = pfmNumGetFromStr(&a, "-123456789.12345");
    if(rc != RC_NRM) {
       PFM_ERR("%s", pfmNumErrorMsg());
       /* Or, PFM_ERR("%s", pfmUtilGetErrorMsg()); */
       return RC_ERR;
    }
    
    rc = pfmNumToInFmtStrN(str, sizeof(str), "####,###", 1, 1, a);
    if(rc != RC_NRM) {
       PFM_ERR("%s", pfmNumErrorMsg());
       /* Or, PFM_ERR("%s", pfmUtilGetErrorMsg()); */
       return RC_ERR;
    }     /* str = -000000123456789.123 */

The following are examples.

Frmt Number Value Buf_ size Align Type Lpad Type Result (v means a space)

#.##

-1.12345

10

0

0

-1.12vvvvv

0.00

-1.12345

10

0

0

-1.12vvvvv

#.#####

-1.12

10

0

0

-1.12vvvvv

0.00000

-1.12

10

0

0

-1.12000vv

##,###

-1234567

10

0

0

-1,234,567v

00,000

-1234567

10

0

0

-1,234,567v

##,###

-1234

10

0

0

-1,234vvvv

00,000

-1234

10

0

0

-1,234vvvv

#,###.##

-123456789.12

20

0

0

-123,456,789.12vvvvv

0,000.00

-123456789.12

20

0

0

-123,456,789.12vvvvv

#,####.##

-123456789.12

20

0

0

-123,456,789.12vvvvv

0,0000.00

-123456789.12

20

0

0

-123,456,789.12vvvvv

#,##,###.##

-123456789.12

20

0

0

Error (Comma separators are allowed only for a specific interval.)

#.#####

-123.12

20

1

0

vvvvvvvvvvvvv-123.12

0.00000

-123.12

20

1

0

vvvvvvvvvv-123.12000

#.##

-123456789.12

20

1

0

vvvvvvv-123456789.12

0.00

-123456789.12

20

1

0

vvvvvvv-123456789.12

#,###.##

-123456789.12

20

1

0

vvvvv-123,456,789.12

0,000.00

-123456789.12

20

1

0

vvvvv-123,456,789.12

#,###.#####

-123456789.12

20

1

0

vvvvv-123,456,789.12

0,000.00000

-123456789.12

20

1

0

vv-123,456,789.12000

#,###.##

-123456789.12

20

1

1

-00000123,456,789.12

0,000.00

-123456789.12

20

1

1

-00000123,456,789.12

#,###.#####

-123456789.12

20

1

1

-00000123,456,789.12

0,000.00000

-123456789.12

20

1

1

-00123,456,789.12000

57. pfmNumPrint

Converts a PfmNumber value to a temporary string for a message.

pfmNumPrint is used to temporarily enter a number value to PFM_DBG, PFM_ERR, and snprintf. Therefore, to convert a value to a string, use other APIs such as pfmNumToStr, pfmNumGetStrLPadZeroN, and pfmNumToCommaStrN.

  • Prototype

    char* pfmNumPrint(PfmNumber x);
  • Parameters

    Parameter Description

    x (input)

    PfmNumber value.

  • Return values

    Returns the pointer to the temporary string for the converted message.

  • Example

    PfmNumber     x;
    
    PfmNumGetFromStr(&x, "-12345678.123");
    if(rc != RC_NRM) {
       PFM_ERR("%s", pfmNumErrorMsg());
       /* Or, PFM_ERR("%s", pfmUtilGetErrorMsg()); */
       return RC_ERR;
    }
    
    if(pfmNumCmp (x, PFMNUM_ZERO) < 0) {
       PFM_ERR("A negative value is entered. [%s]", pfmNumPrint(x));
       return RC_ERR;
    }
    /* Message: "A negative value is entered. [-12345678.123]" */

58. pfmNumPrintComma

Converts a PfmNumber value to a temporary string for a message and adds thousands separators.

pfmNumPrintComma is used to temporarily enter a number value to PFM_DBG, PFM_ERR, and snprintf. Therefore, to convert a value to a string, use other APIs such as pfmNumToStr, pfmNumGetStrLPadZeroN, and pfmNumToCommaStrN.

  • Prototype

    char* pfmNumPrintComma(PfmNumber x);
  • Parameters

    Parameter Description

    x (input)

    PfmNumber value.

  • Return values

    Returns the pointer to the temporary string for the converted message.

  • Example

    PfmNumber     x;
    
    PfmNumGetFromStr(&x, "-12345678.123");
    if(rc != RC_NRM) {
       PFM_ERR("%s", pfmNumErrorMsg());
       /* Or, PFM_ERR("%s", pfmUtilGetErrorMsg()); */
       return RC_ERR;
    }
    
    if(pfmNumCmp (x, PFMNUM_ZERO) < 0) {
       PFM_ERR("A negative value is entered. [%s]", pfmNumPrintComma(x));
       return RC_ERR;
    }
    /* Message: "A negative value is entered. [-12,345,678.123]" */
    
    /* Assembling data to display in a batch program */
    PFM_DBG("The balance of the account number [%s] is KRW %s.", MST->acct_no,
    pfmNumPrintComma(MST->bal_amt));

59. pfmNumFindLocationOfLeastSignificantDigit

Finds the number of decimal places in a PfmNumber value.

  • Prototype

    long pfmNumFindLocationOfLeastSignificantDigit(PfmNumber x);
  • Parameters

    Parameter Description

    x (input)

    PfmNumber value.

  • Return values

    Returns the number of decimal places if the input value has a decimal fraction, or returns the value of (-1) multiplied by the number of zeros located after the first significant figure.

  • Example

    PfmNumber    a;
    long         dp;
    
    if(pfmNumGetFromStr(&a, "123.12") != RC_NRM) {
       PFM_ERR("pfmNumGetFromStr() error");
       return RC_ERR;
    }
    dp = pfmNumFindLocationOfLeastSignificantDigit(a);
    /* dp = 2 */
    /* --------------------------------------------- */
    if(pfmNumFindLocationOfLeastSignificantDigit (amt) > 2) {
       PFM_ERR("A value having less than 3 decimal places is not allowed.");
       return RC_ERR;
    }

    The following are examples.

    Value Result Value

    321.123

    3

    321.12

    2

    321.1

    1

    321

    0

    320

    -1

    300

    -2

    0

    0

60. pfmNumDump

Converts a PfmNumber value to a Hex string.

  • Prototype

    char* pfmNumDump(char *buf, PfmNumber *x);
  • Parameters

    Parameter Description

    *buf (output)

    Result string.

    *x

    PfmNumber value.

  • Example

    PfmNumber    a;
    char str[100]   b = {0,};
    
    if(pfmNumGetFromStr(&a, "12") != RC_NRM) {
       PFM_ERR("pfmNumGetFromStr() Error");
       return RC_ERR;
    }
    pfmNumDump (b, &a);
    /* b = 02,c1,8c,64,b0,ae,00,74,5e,4e,f0,40,2b,20,09,5c,cc,ae,00,6c,e7,ae,00 */

61. pfmNumGetErrorMsg

Returns an error message when a Number utility error occurs.

  • Prototype

    char* pfmNumGetErrorMsg(void);
  • Return values

    Returns the error message.

  • Example

    rc = pfmNumAdd(&a, b, c);
    if(rc != RC_NRM) {
       PFM_ERR("%s", pfmNumGetErrorMsg());
       /* Or, PFM_ERR("%s", pfmUtilGetErrorMsg()); */
       return RC_ERR;
    }