MAOS
Multithreaded Adaptive Optics Simulator
Loading...
Searching...
No Matches
mathmisc.h File Reference

Macros

#define sinc(x)
#define mysqrt(A)

Typedefs

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

Functions

long double factorial (long n1, long n2)
long calc_gcd (long a, long b)
 Compute the greatest common divider.
long calc_lcm (long a, long b)
 Compute the least common multiplier.
long * invperm (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

Macro Definition Documentation

◆ sinc

#define sinc ( x)
Value:
((x)!=0?(sin(M_PI*x)/(M_PI*x)):1)

◆ mysqrt

#define mysqrt ( A)
Value:
(A<0?-sqrt(-A):sqrt(A))

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.

◆ calc_gcd()

long calc_gcd ( long a,
long b )

Compute the greatest common divider.

Parameters
aThe larger value
bThe smaller value
Returns
long The result

◆ calc_lcm()

long calc_lcm ( long a,
long b )

Compute the least common multiplier.

Parameters
a
b
Returns
long

◆ 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.