This repository has been archived on 2020-06-07. You can view files and clone it, but cannot push or open issues or pull requests.
php-armadillo/src/functions.cc

61 lines
1.3 KiB
C++

//
// php-armadillo/functions.cc
//
// @Author CismonX
//
#include "functions.hh"
#include "complex.hh"
#define PHP_ARMA_FE(func) \
ZEND_RAW_FENTRY("Arma\\" #func, ZEND_FN(func), nullptr, 0)
namespace php_arma
{
PHP_FUNCTION(cx_double)
{
double real = 0.;
double imag = 0.;
ZEND_PARSE_PARAMETERS_START(0, 2)
Z_PARAM_OPTIONAL
Z_PARAM_DOUBLE(real)
Z_PARAM_DOUBLE(imag)
ZEND_PARSE_PARAMETERS_END();
zval_set_scalar(return_value, std::complex<double>(real, imag));
}
PHP_FUNCTION(j)
{
double imag = 1.;
ZEND_PARSE_PARAMETERS_START(0, 1)
Z_PARAM_OPTIONAL
Z_PARAM_DOUBLE(imag)
ZEND_PARSE_PARAMETERS_END();
zval_set_scalar(return_value, std::complex<double>(0., imag));
}
PHP_FUNCTION(srand)
{
zend_long seed;
ZEND_PARSE_PARAMETERS_START(0, 1)
Z_PARAM_OPTIONAL
Z_PARAM_LONG(seed)
ZEND_PARSE_PARAMETERS_END();
if (EX_NUM_ARGS() == 0) {
arma::arma_rng::set_seed_random();
} else {
arma::arma_rng::set_seed(seed);
}
}
const zend_function_entry functions[] = {
PHP_ARMA_FE(cx_double)
PHP_ARMA_FE(j)
PHP_ARMA_FE(srand)
PHP_FE_END
};
}