MAOS
Multithreaded Adaptive Optics Simulator
mathmisc.h File Reference

Macros

#define sinc(x)   ((x)!=0?(sin(M_PI*x)/(M_PI*x)):1)
 
#define mysqrt(A)   (A<0?-sqrt(-A):sqrt(A))
 

Typedefs

typedef real(* golden_section_fun) (void *param, real x)
 

Functions

long double factorial (long n1, long n2)
 
longinvperm (long *p, long np)
 
void maxminlong (const long *__restrict p, long N, long *__restrict max, long *__restrict min)
 
long nextpow2 (long n)
 
long nextfftsize (long n)
 
unsigned long mylog2 (unsigned long n)
 
real golden_section_search (golden_section_fun f, void *param, real x1, real x4, real tau)
 
spint * readspint (file_t *fp, long *nx, long *ny)
 
int readvec (void *p, uint32_t magic_p, uint32_t magic_file, size_t size, size_t nmemb, file_t *fp)
 

Detailed Description

A few math routines

Function Documentation

◆ factorial()

long double factorial ( long  n1,
long  n2 
)

Compute the factorial from n1 to n2. Overflow LONG if n2>20, so we use double as output.

◆ invperm()

long* invperm ( long p,
long  np 
)

Reverse an permution vector. A=B(p) <==> A(pi)=B

◆ maxminlong()

void maxminlong ( const long *__restrict  p,
long  N,
long *__restrict  max,
long *__restrict  min 
)

Compute max, min and sum of a long vector

◆ nextpow2()

long nextpow2 ( long  n)

Find the next number that is power of 2.

◆ nextfftsize()

long nextfftsize ( long  n)

Find the next number suitable for FFT. Use radix of 2, 3, 5, 7, 11

◆ readspint()

spint* readspint ( file_t *  fp,
long nx,
long ny 
)

Read spint array of size nx*ny from file and do optional data conversion.

◆ readvec()

int readvec ( void *  p,
uint32_t  magic_p,
uint32_t  magic_file,
size_t  size,
size_t  nmemb,
file_t *  fp 
)

Read a vector from file and perform conversion if type mismatches.