NAME

SPVM::Math - SPVM Math Functions

CAUTHION

SPVM is yet before 1.0 released. SPVM is changed without warnings. There will be quite a lot of changes until I feel enough good.

SYNOPSYS

Perl

use SPVM 'Math';

my $sin = SPVM::Math->sin(SPVM::Math->PI / 4);

SPVM

use Math;

my $sin = Math->sin(Math->PI / 4);

DESCRIPTION

SPVM::Math is a SPVM module that defines mathmatical functions.

EXAMPELS

Complex Tutorial

SPVM provides common arithmetic for complex numbers at the same level as C99.

Complex Type

Complex Type is Complex_2f for complex float and Complex_2d for complex double. Complex_2f and Complex_2d is Multi Numeric Type. This is allocated on Method Call Stack. This is not Object Type which is allocated on Heap Memory. See SPVM Complex Examples at first.

Complex_2f

# Complex float type
use Complex_2f;

my $z : Complex_2f;
$z->{re} = 1.5f;
$z->{im} = 1.7f;

Complex_2d

# Complex double type
use Complex_2d;

my $z : Complex_2d;
$z->{re} = 1.5;
$z->{im} = 1.7;

New Complex Functions

New Complex functions
use Math (complexf, complex);

# Complex_2f
my $z = complexf(1.5f, 1.7f);

# Complex_2d
my $z = complex(1.5, 1.7);

Complex Operation

float Complex Addition, Subtract, Multiply, Scalar Multiply, Division

float Complex Addition, Subtract, Multiply, Scalar Multiply, Division.
# float Addition, Subtract, Multiply, Scalar Multiply, Division functions
use Math(caddf, csubf, cmulf, cscamulf, cdivf);

my $z1 = complexf(1.5f, 1.7f);
my $z2 = complexf(2.5f, 2.7f);

# Addition
my $z_add = caddf($z1, $z2);

# Subtract
my $z_method = csubf($z1, $z2);

# Multiply
my $z_mul = cmulf($z1, $z2);

# Scalar Multiply
my $z_scamul = cscamulf(3, $z2);

# Division
my $z_div = cdivf($z1, $z2);

double Complex Addition, Subtract, Multiply, Scalar Multiply, Division

# double Addition, Subtract, Multiply, Scalar Multiply, Division functions
use Math(cadd, csub, cmul, cscamul, cdiv);

my $z1 = complex(1.5, 1.7);
my $z2 = complex(2.5, 2.7);

# Addition
my $z_add = cadd($z1, $z2);

# Subtract
my $z_method = csub($z1, $z2);

# Multiply
my $z_mul = cmul($z1, $z2);

# Scalar Multiply
my $z_scamul = cscamul(3, $z2);

# Division
my $z_div = cdiv($z1, $z2);

Trigonometric functions

Trigonometric functions.

float Trigonometric functions

float Trigonometric functions.
# float Trigonometric functions
use Math(csinf, ccosf, ctanf);

my $z = complexf(1.5f, 1.7f);

# Addition
my $z_sin = csinf($z);

# Subtract
my $z_cos = ccosf($z);

# Multiply
my $z_tan = ctanf($z);

double Trigonometric functions

double Trigonometric functions.
# double Trigonometric functions
use Math(csin, ccos, ctan);

my $z = complex(1.5, 1.7);

# Addition
my $z_sin = csin($z);

# Subtract
my $z_cos = ccos($z);

# Multiply
my $z_tan = ctan($z);
See Math for more complex functions

Complex Array

SPVM Array of Complex has values arranged in contiguous memory areas.

Complex_2f[]

# Complex float type
use Complex_2f;

my $zs = new Complex_2f[100];

for (my $i = 0; $i < @$zs; $i++) {
  my $z = $zs->[$i];
  $z->{re} = 1.5f;
  $z->{im} = 1.7f;
}

Complex_2d

# Complex double type
use Complex_2d;

my $zs = new Complex_2d[100];

for (my $i = 0; $i < @$zs; $i++) {
  my $z = $zs->[$i];
  $z->{re} = 1.5;
  $z->{im} = 1.7;
}

Call complex function from Perl

Call complex function from Perl. Argument is passed and return value is return.
use SPVM 'MyComplex';

my $z1 = {re => 1.7, im => 2.7};
my $z2 = {re => 7.5, im => 2.5};

my $z_ret = MyComplex->complex_call_from_perl($z1, $z2);

print "($z_ret->{re}, $z_ret->{im})\n";

CLASS METHODS

abs

static method abs : int ($x : int);

Get the abusolute value of a int value.

acos

static method acos : double ($x : double)

acos function defined in C language math.h.

acosf

static method acosf : float ($x : float)

acosf function defined in C language math.h.

acosh

static method acosh : double ($x : double)

acosh function defined in C language math.h.

acoshf

static method acoshf : float ($x : float)

acoshf function defined in C language math.h.

asin

static method asin : double ($x : double)

asin function defined in C language math.h.

asinf

static method asinf : float ($x : float)

asinf function defined in C language math.h.

asinh

static method asinh : double ($x : double)

asinh function defined in C language math.h.

asinhf

static method asinhf : float ($x : float)

asinhf function defined in C language math.h.

atan

static method atan : double ($x : double)

atan function defined in C language math.h.

atan2

static method atan2 : double ($y : double, $x : double)

atan2 function defined in C language math.h.

atanf

static method atanf : float ($x : float)

atanf function defined in C language math.h.

atanh

static method atanh : double ($x : double)

atanh function defined in C language math.h.

atanhf

static method atanhf : float ($x : float)

atanhf function defined in C language math.h.

cabs

static method cabs : double ($z : Complex_2d)

cabs function defined in C language complex.h.

cabsf

static method cabsf : float ($z : Complex_2f)

cabsf function defined in C language complex.h.

cacos

static method cacos : Complex_2d ($z : Complex_2d)

cacos function defined in C language complex.h.

cacosf

static method cacosf : Complex_2f ($z : Complex_2f)

cacosf function defined in C language complex.h.

cacosh

static method cacosh : Complex_2d ($z : Complex_2d)

cacosh function defined in C language complex.h.

cacoshf

static method cacoshf : Complex_2f ($z : Complex_2f)

cacoshf function defined in C language complex.h.

cadd

static method cadd : Complex_2d ($z1 : Complex_2d, $z2 : Complex_2d)

cadd function defined in C language complex.h.

caddf

static method caddf : Complex_2f ($z1 : Complex_2f, $z2 : Complex_2f)

caddf function defined in C language complex.h.

carg

static method carg : double ($z : Complex_2d)

carg function defined in C language complex.h.

cargf

static method cargf : float ($z : Complex_2f)

cargf function defined in C language complex.h.

casin

static method casin : Complex_2d ($z : Complex_2d)

casin function defined in C language complex.h.

casinf

static method casinf : Complex_2f ($z : Complex_2f)

casinf function defined in C language complex.h.

casinh

static method casinh : Complex_2d ($z : Complex_2d)

casinh function defined in C language complex.h.

casinhf

static method casinhf : Complex_2f ($z : Complex_2f)

casinhf function defined in C language complex.h.

catan

static method catan : Complex_2d ($z : Complex_2d)

catan function defined in C language complex.h.

catanf

static method catanf : Complex_2f ($z : Complex_2f)

catanf function defined in C language complex.h.

catanh

static method catanh : Complex_2d ($z : Complex_2d)

catanh function defined in C language complex.h.

catanhf

static method catanhf : Complex_2f ($z : Complex_2f)

catanhf function defined in C language complex.h.

cbrt

static method cbrt : double ($x : double)

cbrt function defined in C language math.h.

cbrtf

static method cbrtf : float ($x : float)

cbrtf function defined in C language math.h.

ccos

static method ccos : Complex_2d ($z : Complex_2d)

ccos function defined in C language complex.h.

ccosf

static method ccosf : Complex_2f ($z : Complex_2f)

ccosf function defined in C language complex.h.

ccosh

static method ccosh : Complex_2d ($z : Complex_2d)

ccosh function defined in C language complex.h.

ccoshf

static method ccoshf : Complex_2f ($z : Complex_2f)

ccoshf function defined in C language complex.h.

cdiv

static method cdiv : Complex_2d ($z1 : Complex_2d, $z2 : Complex_2d)

double complex division.

cdivf

static method cdivf : Complex_2f ($z1 : Complex_2f, $z2 : Complex_2f)

float complex division.

ceil

static method ceil : double ($x : double)

ceil function defined in C language math.h.

ceilf

static method ceilf : float ($x : float)

ceilf function defined in C language math.h.

cexp

static method cexp : Complex_2d ($z : Complex_2d)

cexp function defined in C language complex.h.

cexpf

static method cexpf : Complex_2f ($z : Complex_2f)

cexpf function defined in C language complex.h.

clog

static method clog : Complex_2d ($z : Complex_2d)

clog function defined in C language complex.h.

clogf

static method clogf : Complex_2f ($z : Complex_2f)

clogf function defined in C language complex.h.

cmul

static method cmul : Complex_2d ($z1 : Complex_2d, $z2 : Complex_2d)

double complex multiplication.

cmulf

static method cmulf : Complex_2f ($z1 : Complex_2f, $z2 : Complex_2f)

float complex multiplication.

complex

static method complex : Complex_2d ($x : double, $y : double)

Create double complex value. This value is defined in Complex_2d.

complexf

static method complexf : Complex_2f ($x : float, $y : float)

Create float complex value. This value is defined in Complex_2f.

conj

static method conj : Complex_2d ($z : Complex_2d)

conj function defined in C language complex.h.

conjf

static method conjf : Complex_2f ($z : Complex_2f)

conjf function defined in C language complex.h.

copysign

static method copysign : double ($x1 : double, $x2 : double)

copysign function defined in C language math.h.

copysignf

static method copysignf : float ($x1 : float, $x2 : float)

copysignf function defined in C language math.h.

cos

static method cos : double ($x : double)

cos function defined in C language math.h.

cosf

static method cosf : float ($x : float)

cosf function defined in C language math.h.

cosh

static method cosh : double ($x : double)

cosh function defined in C language math.h.

coshf

static method coshf : float ($x : float)

coshf function defined in C language math.h.

cpow

static method cpow : Complex_2d ($z1 : Complex_2d, $z2 : Complex_2d)

cpow function defined in C language complex.h.

cpowf

static method cpowf : Complex_2f ($z1 : Complex_2f, $z2 : Complex_2f)

cpowf function defined in C language complex.h.

cscamul

static method cscamul : Complex_2d ($c : double, $z : Complex_2d)

double complex scalar multiplication.

cscamulf

static method cscamulf : Complex_2f ($c : float, $z : Complex_2f)

float complex scalar multiplication.

csin

static method csin : Complex_2d ($z : Complex_2d)

csin function defined in C language complex.h.

csinf

static method csinf : Complex_2f ($z : Complex_2f)

csinf function defined in C language complex.h.

csinh

static method csinh : Complex_2d ($z : Complex_2d)

csinh function defined in C language complex.h.

csinhf

static method csinhf : Complex_2f ($z : Complex_2f)

csinhf function defined in C language complex.h.

csqrt

static method csqrt : Complex_2d ($z : Complex_2d)

csqrt function defined in C language complex.h.

csqrtf

static method csqrtf : Complex_2f ($z : Complex_2f)

csqrtf function defined in C language complex.h.

csub

static method csub : Complex_2d ($z1 : Complex_2d, $z2 : Complex_2d)

csub function defined in C language complex.h.

csubf

static method csubf : Complex_2f ($z1 : Complex_2f, $z2 : Complex_2f)

csubf function defined in C language complex.h.

ctan

static method ctan : Complex_2d ($z : Complex_2d)

ctan function defined in C language complex.h.

ctanf

static method ctanf : Complex_2f ($z : Complex_2f)

ctanf function defined in C language complex.h.

ctanh

static method ctanh : Complex_2d ($z : Complex_2d)

ctanh function defined in C language complex.h.

ctanhf

static method ctanhf : Complex_2f ($z : Complex_2f)

ctanhf function defined in C language complex.h.

E

static method E : double ()

Euler’s Number e. This value is 0x1.5bf0a8b145769p+1.

erf

static method erf : double ($x : double)

erf function defined in C language math.h.

erfc

static method erfc : double ($x : double)

erfc function defined in C language math.h.

erfcf

static method erfcf : float ($x : float)

erfcf function defined in C language math.h.

erff

static method erff : float ($x : float)

erff function defined in C language math.h.

exp

static method exp : double ($x : double)

exp function defined in C language math.h.

exp2

static method exp2 : double ($x : double)

exp2 function defined in C language math.h.

exp2f

static method exp2f : float ($x : float)

exp2f function defined in C language math.h.

expf

static method expf : float ($x : float)

expf function defined in C language math.h.

expm1

static method expm1 : double ($x : double)

expm1 function defined in C language math.h.

expm1f

static method expm1f : float ($x : float)

expm1f function defined in C language math.h.

fabs

static method fabs : double ($x : double)

fabs function defined in C language math.h.

fabsf

static method fabsf : float ($x : float)

fabsf function defined in C language math.h.

fdim

static method fdim : double ($x1 : double, $x2 : double)

fdim function defined in C language math.h.

fdimf

static method fdimf : float ($x1 : float, $x2 : float)

fdimf function defined in C language math.h.

FE_DOWNWARD

static method FE_DOWNWARD : int ()

FE_DOWNWARD macro defined in C language fenv.h.

FE_TONEAREST

static method FE_TONEAREST : int ()

FE_TONEAREST macro defined in C language fenv.h.

FE_TOWARDZERO

static method FE_TOWARDZERO : int ()

FE_TOWARDZERO macro defined in C language fenv.h.

FE_UPWARD

static method FE_UPWARD : int ()

FE_UPWARD macro defined in C language fenv.h.

fesetround

static method fesetround : int ($round : int)

fesetround function defined in C language math.h.

floor

static method floor : double ($x : double)

floor function defined in C language math.h.

floorf

static method floorf : float ($x : float)

floorf function defined in C language math.h.

fma

static method fma : double ($x1 : double, $x2 : double, $x3 : double)

fma function defined in C language math.h.

fmaf

static method fmaf : float ($x1 : float, $x2 : float, $x3 : float)

fmaf function defined in C language math.h.

fmax

static method fmax : double ($x1 : double, $x2 : double)

fmax function defined in C language math.h.

fmaxf

static method fmaxf : float ($x1 : float, $x2 : float)

fmaxf function defined in C language math.h.

fmin

static method fmin : double ($x1 : double, $x2 : double)

fmin function defined in C language math.h.

fminf

static method fminf : float ($x1 : float, $x2 : float)

fminf function defined in C language math.h.

fmod

static method fmod : double ($x1 : double, $x2 : double)

fmod function defined in C language math.h.

fmodf

static method fmodf : float ($x1 : float, $x2 : float)

fmodf function defined in C language math.h.

FP_ILOGB0

static method FP_ILOGB0 : int ()

FP_ILOGB0 macro defined in C language fenv.h.

FP_ILOGBNAN

static method FP_ILOGBNAN : int ()

FP_ILOGBNAN macro defined in C language fenv.h.

FP_INFINITE

static method FP_INFINITE : int ()

FP_INFINITE macro defined in C language fenv.h.

FP_NAN

static method FP_NAN : int ()

FP_NAN macro defined in C language fenv.h.

FP_ZERO

static method FP_ZERO : int ()

FP_ZERO macro defined in C language fenv.h.

fpclassify

static method fpclassify : int ($x : double)

fpclassify macro defined in C language math.h. This method receives a double value.

fpclassifyf

static method fpclassifyf : int ($x : float)

fpclassify macro defined in C language math.h for float type. This method receives a float value.

frexp

static method frexp : double ($x : double, $exp : int&)

frexp function defined in C language math.h.

frexpf

static method frexpf : float ($x : float, $exp : int&)

frexpf function defined in C language math.h.

HUGE_VAL

static method HUGE_VAL : double ()

HUGE_VAL macro defined in C language math.h.

HUGE_VALF

static method HUGE_VALF : float ()

HUGE_VALF macro defined in C language math.h.

hypot

static method hypot : double ($x : double, $y : double)

hypot function defined in C language math.h.

hypotf

static method hypotf : float ($x : float, $y : float)

hypotf function defined in C language math.h.

ilogb

static method ilogb : int ($x : double)

ilogb function defined in C language math.h.

ilogbf

static method ilogbf : int ($x : float)

ilogbf function defined in C language math.h.

INFINITY

static method INFINITY : double ()

INFINITY macro defined in C language math.h. This method returns a double value.

INFINITYF

static method INFINITYF : float ()

INFINITY macro for float type defined in C language math.h. This method returns a float value.

isfinite

static method isfinite : int ($x : double)

isfinite macro defined in C language math.h. This method receives a double value.

isfinitef

static method isfinitef : int($x : float)

isfinite macro defined in C language math.h for float type. This method receives a float value.

isgreater

static method isgreater : int ($x1 : double, $x2 : double)

isgreater macro defined in C language math.h. This method receives two double values.

isgreaterequal

static method isgreaterequal : int ($x1 : double, $x2 : double)

isgreaterequal macro defined in C language math.h. This method receives two double values.

isgreaterequalf

static method isgreaterequalf : int ($x1 : float, $x2 : float)

isgreaterequal macro defined in C language math.h. This method receives two float values.

isgreaterf

static method isgreaterf : int ($x1 : float, $x2 : float)

isgreater macro defined in C language math.h. This method receives two float values.

isinf

static method isinf : int ($x : double)

isinf macro defined in C language math.h. This method receives a double value.

isinff

static method isinff : int($x : float)

isinf macro defined in C language math.h. This method receives a float value.

isless

static method isless : int ($x1 : double, $x2 : double)

isless macro defined in C language math.h. This method receives two double values.

islessequal

static method islessequal : int ($x1 : double, $x2 : double)

islessequal macro defined in C language math.h. This method receives two double values.

islessequalf

static method islessequalf : int ($x1 : float, $x2 : float)

islessequalf macro defined in C language math.h. This method receives two float values.

islessf

static method islessf : int ($x1 : float, $x2 : float)

islessf macro defined in C language math.h. This method receives two float values.

islessgreater

static method islessgreater : int ($x1 : double, $x2 : double)

islessgreater macro defined in C language math.h. This method receives two double values.

islessgreaterf

static method islessgreaterf : int ($x1 : float, $x2 : float)

islessgreater macro defined in C language math.h. This method receives two float values.

isnan

static method isnan : int ($x : double)

isnan macro defined in C language math.h. This method receives a double value.

isnanf

static method isnanf : int ($x : float)

isnanf macro defined in C language math.h. This method receives a float value.

isunordered

static method isunordered : int ($x1 : double, $x2 : double)

isunordered macro defined in C language math.h. This method receives two double values.

isunorderedf

static method isunorderedf : int ($x1 : float, $x2 : float)

isunorderedf macro defined in C language math.h. This method receives two float values.

labs

static method labs : long ($x : long);

Get the abusolute value of a long value.

ldexp

static method ldexp : double ($x : double, $exp : int)

ldexp function defined in C language math.h.

ldexpf

static method ldexpf : float ($x : float, $exp : int)

ldexpf function defined in C language math.h.

lgamma

static method lgamma : double ($x : double)

lgamma function defined in C language math.h.

lgammaf

static method lgammaf : float ($x : float)

lgammaf function defined in C language math.h.

log

static method log : double ($x : double)

log function defined in C language math.h.

log10

static method log10 : double ($x : double)

log10 function defined in C language math.h.

log10f

static method log10f : float ($x : float)

log10f function defined in C language math.h.

log1p

static method log1p : double ($x : double)

log1p function defined in C language math.h.

log1pf

static method log1pf : float ($x : float)

log1pf function defined in C language math.h.

log2

static method log2 : double ($x : double)

log2 function defined in C language math.h.

log2f

static method log2f : float ($x : float)

log2f function defined in C language math.h.

logb

static method logb : double ($x : double)

logb function defined in C language math.h.

logbf

static method logbf : float ($x : float)

logbf function defined in C language math.h.

logf

static method logf : float ($x : float)

logf function defined in C language math.h.

lround

static method lround : long ($x : double)

llround function defined in C language math.h. Note that call llround instead of lround in C level.

lroundf

static method lroundf : long ($x : float)

llroundf function defined in C language math.h. Note that call llroundf instead of lroundf in C level.

modf

static method modf : double ($x : double, $intpart : double&)

modf function defined in C language math.h.

modff

static method modff : float ($x : float, $intpart : float&)

modff function defined in C language math.h.

NAN

static method NAN : double ()

NAN macro defined in C language math.h. This method return a double value.

nan

static method nan : double ($str : string)

nan function defined in C language math.h.

String must be defined, otherwise a exception occurs.

NANF

static method NANF : float ()

NAN macro defined in C language math.h. This method return a float value.

nanf

static method nanf : float ($str : string)

nanf function defined in C language math.h.

String must be defined, otherwise a exception occurs.

nearbyint

static method nearbyint : double ($x : double)

nearbyint function defined in C language math.h.

nearbyintf

static method nearbyintf : float ($x : float)

nearbyintf function defined in C language math.h.

nextafter

static method nextafter : double ($x1 : double, $x2 : double)

nextafter function defined in C language math.h.

nextafterf

static method nextafterf : float ($x1 : float, $x2 : float)

nextafterf function defined in C language math.h.

nexttoward

static method nexttoward : double ($x1 : double, $x2 : double)

nexttoward function defined in C language math.h.

nexttowardf

static method nexttowardf : float ($x1 : float, $x2 : double)

nexttowardf function defined in C language math.h.

PI

static method PI : double ()

pi. This value is 0x1.921fb54442d18p+1.

pow

static method pow : double ($x : double, $y : double)

pow function defined in C language math.h.

powf

static method powf : float ($x : float, $y : float)

powf function defined in C language math.h.

remainder

static method remainder : double ($x1 : double, $x2 : double)

remainder function defined in C language math.h.

remainderf

static method remainderf : float ($x1 : float, $x2 : float)

remainderf function defined in C language math.h.

remquo

static method remquo : double ($x1 : double, $x2 : double, $quo : int&)

remquo function defined in C language math.h.

remquof

static method remquof : float ($x1 : float, $x2 : float, $quo : int&)

remquof function defined in C language math.h.

round

static method round : double ($x : double)

round function defined in C language math.h.

roundf

static method roundf : float ($x : float)

roundf function defined in C language math.h.

scalbln

static method scalbln : double ($x : double, $exp : long)

scalbln function defined in C language math.h.

scalblnf

static method scalblnf : float ($x : float, $exp : long)

scalblnf function defined in C language math.h.

scalbn

static method scalbn : double ($x : double, $exp : int)

scalbn function defined in C language math.h.

scalbnf

static method scalbnf : float ($x : float, $exp : int)

scalbnf function defined in C language math.h.

signbit

static method signbit : int ($x : double)

signbit function defined in C language math.h.

signbitf

static method signbitf : int ($x : float)

signbitf function defined in C language math.h.

sin

static method sin : double ($x : double)

sin function defined in C language math.h.

sinf

static method sinf : float ($x : float)

sinf function defined in C language math.h.

sinh

static method sinh : double ($x : double)

sinh function defined in C language math.h.

sinhf

static method sinhf : float ($x : float)

sinhf function defined in C language math.h.

sqrt

static method sqrt : double ($x : double)

sqrt function defined in C language math.h.

sqrtf

sqrtf function defined in C language math.h.

tan

static method tan : double ($x : double)

tan function defined in C language math.h.

tanf

static method tanf : float ($x : float)

tanf function defined in C language math.h.

tanh

static method tanh : double ($x : double)

tanh function defined in C language math.h.

tanhf

static method tanhf : float ($x : float)

tanhf function defined in C language math.h.

tgamma

static method tgamma : double ($x : double)

tgamma function defined in C language math.h.

tgammaf

static method tgammaf : float ($x : float)

tgammaf function defined in C language math.h.

trunc

static method trunc : double ($x : double)

trunc function defined in C language math.h.

truncf

static method truncf : float ($x : float)

truncf function defined in C language math.h.

1 POD Error

The following errors were encountered while parsing the POD:

Around line 688:

Non-ASCII character seen before =encoding in 'Euler’s'. Assuming UTF-8