forked from JuliaLang/julia
-
Notifications
You must be signed in to change notification settings - Fork 0
/
gen_mathfunctions.sh
executable file
·60 lines (51 loc) · 2.55 KB
/
gen_mathfunctions.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
echo "# This file is autogenerated using gen_mathfunctions.sh"
echo "libm = dlopen(\"libm\")"
echo
for func in sin cos tan sinh cosh tanh asin acos atan log log2 log10 log1p logb exp exp2 expm1 erf erfc sqrt cbrt ceil floor nearbyint round rint trunc; do
echo "# $func"
echo "$func(x::Float64) = ccall(dlsym(libm,\"$func\"), Float64, (Float64,), x)"
echo "$func(x::Float32) = ccall(dlsym(libm,\"${func}f\"), Float32, (Float32,), x)"
echo "$func(x::Scalar) = $func(convert(Float64,x))"
echo "$func(x::Vector) = [ $func(x[i]) | i=1:length(x) ]"
echo "$func(x::Matrix) = [ $func(x[i,j]) | i=1:size(x,1), j=1:size(x,2) ]"
echo
done
echo "# abs"
echo "abs(x::Float64) = ccall(dlsym(libm,\"fabs\"), Float64, (Float64,), x)"
echo "abs(x::Float32) = ccall(dlsym(libm,\"fabsf\"), Float32, (Float32,), x)"
echo "abs(x::Vector) = [ abs(x[i]) | i=1:length(x) ]"
echo "abs(x::Matrix) = [ abs(x[i,j]) | i=1:size(x,1), j=1:size(x,2) ]"
echo
echo "# ldexp"
echo "ldexp(x::Float64,e::Int32) = ccall(dlsym(libm,\"ldexp\"), Float64, (Float64,Int32), x, e)"
echo "ldexp(x::Float32,e::Int32) = ccall(dlsym(libm,\"ldexpf\"), Float32, (Float32,Int32), x, e)"
echo
for func in atan2 pow remainder fmod copysign hypot fmin fmax fdim; do
echo "# $func"
echo "$func(x::Float64, y::Float64) = ccall(dlsym(libm,\"$func\"), Float64, (Float64, Float64,), x, y)"
echo "$func(x::Float32, y::Float32) = ccall(dlsym(libm,\"${func}f\"), Float32, (Float32, Float32), x, y)"
echo "$func(x::Scalar, y::Scalar) = $func(convert(Float64,x),convert(Float64,y))"
echo
done
for func in isinf isnan; do
echo "# $func"
echo "$func(x::Float64) = ccall(dlsym(libm,\"$func\"), Int32, (Float64,), x)!=0"
echo "$func(x::Float32) = ccall(dlsym(libm,\"${func}f\"), Int32, (Float32,), x)!=0"
echo "$func(x::Int) = false"
echo "$func(x::Vector) = [ $func(x[i]) | i=1:length(x) ]"
echo "$func(x::Matrix) = [ $func(x[i,j]) | i=1:size(x,1), j=1:size(x,2) ]"
echo
done
for func in lrint lround ilogb; do
echo "# $func"
echo "$func(x::Float64) = ccall(dlsym(libm,\"$func\"), Int32, (Float64,), x)"
echo "$func(x::Float32) = ccall(dlsym(libm,\"${func}f\"), Int32, (Float32,), x)"
echo "$func(x::Vector) = [ $func(x[i]) | i=1:length(x) ]"
echo "$func(x::Matrix) = [ $func(x[i,j]) | i=1:size(x,1), j=1:size(x,2) ]"
echo
done
echo "# rand"
echo "rand() = ccall(dlsym(JuliaDLHandle,\"rand_double\"), Float64, ())"
echo "randf() = ccall(dlsym(JuliaDLHandle,\"rand_float\"), Float32, ())"
echo "randint() = ccall(dlsym(JuliaDLHandle,\"genrand_int32\"), Uint32, ())"
echo