arbitrary floating precision number to string

nkvnkv

I am new to c programming language. What I am trying to do is to get store pi in arbitary precision and turn that to string.

int calculatePIConst (int preciznost)
{
    //init var
    mpfr_t x;
    mpfr_init2 (x, preciznost);
    //populate pi
    mpfr_const_pi (x, MPFR_RNDN);
    //turn to string
    char abc[preciznost];
    int i;
    //error RUN FINISHED; Segmentation fault; core dumped; real time: 90ms; user: 0ms; system: 0ms
    //  mpfr_get_str (abc, i, 50, 50, x, MPFR_RNDN);
    //write pi
    mpfr_printf ("PI = %1.1024RNf\n", x);
    mpfr_clear (x);
    return *abc;
}

Here is mpfr lib documentation documentation http://www.mpfr.org/mpfr-current/mpfr.html#Miscellaneous-Functions

r3mainer

From the documentation you linked to:

If str is not a null pointer, it should point to a block of storage large enough for the significand, i.e., at least max(n + 2, 7). The extra two bytes are for a possible minus sign, and for the terminating null character, and the value 7 accounts for -@Inf@ plus the terminating null character.

Also, I assume you want your result in base 10, not base 50.

Try this:

char abc[preciznost + 2]; /* assuming preciznost >= 5 */
  :
mpfr_get_str (abc, i, 10, 50, x, MPFR_RNDN);

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Converting an arbitrary-precision rational number (OCaml, zarith) to an approximate floating number

From Dev

stripe node arbitrary precision number

From Dev

Which programming languages have arbitrary precision floating-point literals?

From Dev

Python: forcing precision on a floating point number in json?

From Java

How to deal with floating point number precision in JavaScript?

From Dev

Apache Pig floating number SUM error in precision

From Dev

using printf to print a floating number with varying precision

From Dev

Variable floating-point precision format string

From Dev

String format double with arbitrary precision, fixed decimal position

From Dev

How to obtain only the integer part of a long floating precision number with JS?

From Dev

Handling a quadruple precision floating point (128-bit) number in java

From Dev

Assembly - Round floating point number to .001 precision toward -∞

From Dev

what is it called when a floating point number is larger than its precision?

From Dev

Converting base of floating point number without losing precision

From Dev

Can you set the qDebug() floating point precision and number format globally?

From Dev

Converting base of floating point number without losing precision

From Dev

fast computation for extended precision floating point for number theory application

From Dev

Handling a quadruple precision floating point (128-bit) number in java

From Dev

Why precision problems in a floating point number varies according to values?

From Dev

How to increase the floating point precision of a number by using BigDecimals in java?

From Dev

LLVM arbitrary precision integer

From Dev

Python mpmath not arbitrary precision?

From Dev

LLVM arbitrary precision integer

From Dev

Floating Point Precision Error

From Dev

precision of floating variables in arduino

From Dev

a floating point precision of X

From Dev

precision of floating point in tensorflow

From Dev

how to format simultaneously a string and floating number in awk?

From Dev

Is there an equivalent of Python's fractions.Fraction (bignum/arbitrary-precision fraction/rational number class)?

Related Related

  1. 1

    Converting an arbitrary-precision rational number (OCaml, zarith) to an approximate floating number

  2. 2

    stripe node arbitrary precision number

  3. 3

    Which programming languages have arbitrary precision floating-point literals?

  4. 4

    Python: forcing precision on a floating point number in json?

  5. 5

    How to deal with floating point number precision in JavaScript?

  6. 6

    Apache Pig floating number SUM error in precision

  7. 7

    using printf to print a floating number with varying precision

  8. 8

    Variable floating-point precision format string

  9. 9

    String format double with arbitrary precision, fixed decimal position

  10. 10

    How to obtain only the integer part of a long floating precision number with JS?

  11. 11

    Handling a quadruple precision floating point (128-bit) number in java

  12. 12

    Assembly - Round floating point number to .001 precision toward -∞

  13. 13

    what is it called when a floating point number is larger than its precision?

  14. 14

    Converting base of floating point number without losing precision

  15. 15

    Can you set the qDebug() floating point precision and number format globally?

  16. 16

    Converting base of floating point number without losing precision

  17. 17

    fast computation for extended precision floating point for number theory application

  18. 18

    Handling a quadruple precision floating point (128-bit) number in java

  19. 19

    Why precision problems in a floating point number varies according to values?

  20. 20

    How to increase the floating point precision of a number by using BigDecimals in java?

  21. 21

    LLVM arbitrary precision integer

  22. 22

    Python mpmath not arbitrary precision?

  23. 23

    LLVM arbitrary precision integer

  24. 24

    Floating Point Precision Error

  25. 25

    precision of floating variables in arduino

  26. 26

    a floating point precision of X

  27. 27

    precision of floating point in tensorflow

  28. 28

    how to format simultaneously a string and floating number in awk?

  29. 29

    Is there an equivalent of Python's fractions.Fraction (bignum/arbitrary-precision fraction/rational number class)?

HotTag

Archive