[CLN-list] how to locate arrays in CLN library

sopik at fzu.cz sopik at fzu.cz
Fri Jun 19 11:49:17 CEST 2009


Hi,
first of all, I'd like to thank you for being interested. You're right, it
wasn't very clever to ask without giving any example code. Here it is

#include <cln/complex.h>
#include <cln/complex_io.h>
#include <cln/float.h>
#include <iostream>

using namespace std;
using namespace cln;
float_format_t default_float_format = float_format(40);

int main(void)
{
	int i, N = 10;
	cl_N *A;

	A = (cl_N*)malloc(sizeof(cl_N)*N);
	for(i=0; i<N; i++) {
		*(A+i) = complex(cl_float(i),cl_float(2));
	}
	for(i=0; i<N; i++) {
		cout << *(A+i) << endl;
	}
	cout << "See, it works!" << endl;
}

The understandable error message is:
Unauthorized access to memory (SIGSEGV)

However I don't know, how to do things properly.
Thank you for any advice.
Breta


> Hi,
>
> sopik at fzu.cz wrote:
>> I'd like to to work with fields of complex numbers of high precision using
>> the CLN library. I can't successfuly allocate the memory using memalloc
however. I tired few possibilities, but nothing worked. There is no
notice
>> about this topic in manual or in mail discussion, so it seems to be
straightforward. But I have no idea how to do it.
>
> I'm not sure what you are trying to do, but working with complex numbers
is straightforward. This is C++ and you should rely on the power of
constructors/destructors and, if necessary, use new/delete for memory
management, instead of malloc/free.
>
> Here is a working mini-example:
>
> #include <cln/cln.h>
> #include <iostream>
> using namespace std;
> using namespace cln;
>
> int main()
> {
>      cl_N x = -4;
>      cl_N sqrt_x = sqrt( x );
>      if ( sqrt_x == complex( 0, 2 ) ) {
>          cout << "See, it works!" << endl;
>      }
> }
>
> If this doesn't help, please post some example code.
>
> Best wishes
>     -rbk.
> --
> Richard B. Kreckel
> <http://www.ginac.de/~kreckel/>
>





More information about the CLN-list mailing list