Learn how easy it is to sync an existing GitHub or Google Code repo to a SourceForge project! See Demo

Close

[de14c2]: @mp / private / mpfr_get_d.c Maximize Restore History

Download this file

mpfr_get_d.c    52 lines (40 with data), 1.3 kB

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
#include <stdio.h>
#include <mpfr.h>
#include "gmp.h"
#include "mex.h"
void mexFunction( int nlhs, mxArray *plhs[],
int nrhs, const mxArray *prhs[] )
{
double *prec,*eout;
int mrows,ncols;
char *input_buf;
int buflen,status;
mpfr_t x;
mp_exp_t expptr;
/* Check for proper number of arguments. */
if(nrhs!=2) {
mexErrMsgTxt("Three inputs required.");
} else if(nlhs>2) {
mexErrMsgTxt("Too many output arguments");
}
/* The input must be a noncomplex scalar double.*/
mrows = mxGetM(prhs[0]);
ncols = mxGetN(prhs[0]);
if( !mxIsDouble(prhs[0]) || mxIsComplex(prhs[0]) ||
!(mrows==1 && ncols==1) ) {
mexErrMsgTxt("Input must be a noncomplex scalar double.");
}
/* Set precision and initialize mpfr variables */
prec = mxGetPr(prhs[0]);
mpfr_set_default_prec(*prec);
mpfr_init(x);/* mpfr_init(y); mpfr_init(z); */
/* Read the input strings into mpfr x and y */
buflen = (mxGetM(prhs[1]) * mxGetN(prhs[1])) + 1;
input_buf=mxCalloc(buflen, sizeof(char));
status = mxGetString(prhs[1], input_buf, buflen);
mpfr_set_str(x,input_buf,10,GMP_RNDN);
plhs[0] = mxCreateDoubleMatrix(mrows,ncols, mxREAL);
eout=mxGetPr(plhs[0]);
*eout=mpfr_get_d(x,GMP_RNDN);;
mpfr_clear(x);
}