I'm trying to figure out gsl - I've just downloaded it.
I'm really confused about how to actually use the functions. I've definitely got everything worked out so I can pull them into my program, but getting the result is more complicated than I thought it would be. Or maybe I'm just being stupid about something. :P
But for example, if I just want to print out a random number, can someone explain how that works (just in general, I might be confused about what the library is itself lol)?
I found the function that returns a random number, and have the appropriate header.
But what do I do with it?
I can't just say printf("%e", -function-)...

All I want to do right now is print out the random number.

Thanks.

06-05-2008

Sebastiani

>> I can't just say printf("&#37;e", -function-)...

I'm not really clear what problem you're having. are you saying you don't know how to call a function? could you post a more complete code snippet of what you've trying to do?

06-05-2008

tabstop

Quote:

Originally Posted by zdream8

I can't just say printf("%e", -function-)...

Why not? What kind of number is returned (%e prints a floating point number)?

06-05-2008

sand_man

Can you post the function definition?

06-05-2008

zdream8

All right, I don't really know what I'm doing, but this is what I have.

Well I feel like this is a pretty simple problem someone should be able to tell me pretty quickly. I think I'm just bad at phrasing the question, since I'm confused. Same with looking things up - if I knew what to do I would know what to look up. :S

Oh, and sand_man the definition, like in the above code, is double gsl_rng_uniform (const gsl_rng * r).

06-05-2008

tabstop

So if the prototype is double gsl_rng_uniform(const gsl_rng *r), you need to have a gsl_rng pointer around (whatever that may happen to be) to pass to the function.

I mean, the prototype for the square root function is double sqrt(double x), but you don't actually call it with "sqrt(double x)", you call it with "sqrt(25.5)", or "sqrt(y)" if y is a double variable.

This makes sense to me because it's a function that depends on x, so you give it an x and it runs.

But I haven't been able to get the rng function to do anything. If I give it something else, it says there's an undefined reference to gsl_rng_uniform (even though it's declared and everything). Or an incompatible type argument.
I've written functions myself and used them and it's been fine... :(
Maybe I'm doing something wrong with the pointer? But I've used pointers before...

06-06-2008

tabstop

So have you looked here? It looks like you need to do some initialization to get a valid gsl_rng pointer thing.

Thanks for your help, everyone, I finally got my whole program to work.
Sorry that was so vague, but I was really confused and there were a few problems. :S But anyway, thanks again. I'll probably be back, but I'm okay for now.