gmp_lib.mpz_get_d_2exp Method

GMP Native Interface for .NET

gmp_libmpz_get_d_2exp Method
Convert op to a double, truncating if necessary (i.e. rounding towards zero), and returning the exponent separately.

Namespace:  Math.Gmp.Native
Assembly:  Math.Gmp.Native (in Math.Gmp.Native.dll) Version: 1.0.0.0 (1.0.0.0)
Syntax
public static double mpz_get_d_2exp(
	ref int exp,
	mpz_t op
)
Public Shared Function mpz_get_d_2exp ( 
	ByRef exp As Integer,
	op As mpz_t
) As Double
public:
static double mpz_get_d_2exp(
	int% exp, 
	mpz_t^ op
)
static member mpz_get_d_2exp : 
        exp : int byref * 
        op : mpz_t -> float 

Parameters

exp
Type: SystemInt32
The returned exponent.
op
Type: Math.Gmp.Nativempz_t
The integer.

Return Value

Type: Double
op as a double, truncating if necessary (i.e. rounding towards zero).
Remarks

The return value is in the range 0.5 ≤ | d | < 1 and the exponent is stored to exp. d x 2^exp is the (truncated) op value. If op is zero, the return value is 0.0 and 0 is stored to exp.

This is similar to the standard C frexp function.

Examples
// Create, initialize, and set the value of x to 2^20.
mpz_t x = new mpz_t();
char_ptr value = new char_ptr("100000000000000000000");
gmp_lib.mpz_init_set_str(x, value, 2);

// Assert that x is equal to 0.5^21.
int exp = 0;
Assert.IsTrue(gmp_lib.mpz_get_d_2exp(ref exp, x) == 0.5D);
Assert.IsTrue(exp == 21);

// Release unmanaged memory allocated for x and the string value.
gmp_lib.mpz_clear(x);
gmp_lib.free(value);
' Create, initialize, and set the value of x to 2^20.
Dim x As New mpz_t()
Dim value As New char_ptr("100000000000000000000")
gmp_lib.mpz_init_set_str(x, value, 2)

' Assert that x is equal to 0.5^21.
Dim exp As Integer = 0
Assert.IsTrue(gmp_lib.mpz_get_d_2exp(exp, x) = 0.5)
Assert.IsTrue(exp = 21)

' Release unmanaged memory allocated for x and the string value.
gmp_lib.mpz_clear(x)
gmp_lib.free(value)

No code example is currently available or this language may not be supported.

No code example is currently available or this language may not be supported.

See Also