Drexel dragonThe Math ForumDonate to the Math Forum



Search All of the Math Forum:

Views expressed in these public forums are not endorsed by Drexel University or The Math Forum.


Math Forum » Discussions » Software » comp.soft-sys.matlab

Topic: mex gateway function
Replies: 5   Last Post: Jan 3, 2013 6:02 PM

Advanced Search

Back to Topic List Back to Topic List Jump to Tree View Jump to Tree View   Messages: [ Previous | Next ]
James Tursa

Posts: 2,069
Registered: 8/5/09
Re: mex gateway function
Posted: Jan 3, 2013 6:02 PM
  Click to see the message monospaced in plain text Plain Text   Click to reply to this topic Reply

"Michal Kvasnicka" wrote in message <kc3uq0$t49$1@newscl01ah.mathworks.com>...
> How to create suitable mex gateway function coresponduing to the following C function (decimal to binary conversion)?
>
> void deci2bin( int x, int n, double* output){
> double *temp;
> int i;
> temp = (double *)mxMalloc(sizeof(double)*n);
> i=0;
> while(x>=0 && i<n){
> temp[i] = x%2;
> i++;
> }
> for(i=0;i<n;i++)
> output[i] = temp[n-1-i];
> }


In addition to looking for a fast utility, you should probably be looking for a correct one as well. I don't see how the above routine can work at all since x is not altered during the while loop extracting the "bits" via the x%2 operation. Also, what is supposed to happen for negative x inputs? In the above code, you will end up copying unitialized memory into output for this case. Bottom line is the above code has bugs that need fixing.

James Tursa



Point your RSS reader here for a feed of the latest messages in this topic.

[Privacy Policy] [Terms of Use]

© Drexel University 1994-2014. All Rights Reserved.
The Math Forum is a research and educational enterprise of the Drexel University School of Education.