gmp_libmpz_inp_raw Method |
Namespace: Math.Gmp.Native
This routine can read the output from mpz_out_raw(ptrFILE, mpz_t) also from GMP 1, in spite of changes necessary for compatibility between 32-bit and 64-bit machines.
// Create, initialize, and set the value of op to 123456. mpz_t op = new mpz_t(); gmp_lib.mpz_init_set_ui(op, 123456U); // Write op to a temporary file. string pathname = System.IO.Path.GetTempFileName(); ptr<FILE> stream = new ptr<FILE>(); _wfopen_s(out stream.Value.Value, pathname, "w"); Assert.IsTrue(gmp_lib.mpz_out_raw(stream, op) == 7); fclose(stream.Value.Value); // Read op from the temporary file, and assert that the number of bytes read is 6. _wfopen_s(out stream.Value.Value, pathname, "r"); Assert.IsTrue(gmp_lib.mpz_inp_raw(op, stream) == 7); fclose(stream.Value.Value); // Assert that op is 123456. Assert.IsTrue(gmp_lib.mpz_get_ui(op) == 123456U); // Delete temporary file. System.IO.File.Delete(pathname); // Release unmanaged memory allocated for op. gmp_lib.mpz_clear(op);