gnu_mpc 0.8.0
Sign up to get free protection for your applications and to get access to all the features.
- data/COPYING.md +13 -0
- data/Gemfile +17 -0
- data/Guardfile +18 -0
- data/Makefile +12 -0
- data/README.md +47 -0
- data/Rakefile +54 -0
- data/ext/extconf.rb +46 -0
- data/ext/mpc.c +1010 -0
- data/ext/mpcrnd.c +194 -0
- data/ext/ruby_gmp.h +343 -0
- data/ext/ruby_mpc.h +63 -0
- data/lib/mpc.rb +30 -0
- data/manual.md +933 -0
- data/manual.pdf +0 -0
- data/manual_template.latex +177 -0
- data/spec/acos_spec.rb +66 -0
- data/spec/add_args_spec.rb +51 -0
- data/spec/add_fr_spec.rb +54 -0
- data/spec/add_spec.rb +32 -0
- data/spec/asin_spec.rb +66 -0
- data/spec/atan_spec.rb +109 -0
- data/spec/conj_spec.rb +56 -0
- data/spec/cos_spec.rb +54 -0
- data/spec/cosh_spec.rb +26 -0
- data/spec/exp_spec.rb +62 -0
- data/spec/hash_arguments_spec.rb +17 -0
- data/spec/log_spec.rb +37 -0
- data/spec/mpc_single_function_args_spec.rb +41 -0
- data/spec/neg_spec.rb +30 -0
- data/spec/new_spec.rb +97 -0
- data/spec/proj_spec.rb +20 -0
- data/spec/real_spec.rb +23 -0
- data/spec/rounding_spec.rb +199 -0
- data/spec/sin_spec.rb +66 -0
- data/spec/sinh_spec.rb +65 -0
- data/spec/spec_helper.rb +1 -0
- data/spec/sqr_spec.rb +96 -0
- data/spec/sqrt_spec.rb +72 -0
- data/spec/sub_spec.rb +50 -0
- data/spec/tan_spec.rb +55 -0
- data/spec/tanh_spec.rb +53 -0
- data/spec/to_s_spec.rb +77 -0
- data/spec/version_spec.rb +7 -0
- metadata +91 -0
data/manual.pdf
ADDED
Binary file
|
@@ -0,0 +1,177 @@
|
|
1
|
+
\documentclass[$if(fontsize)$$fontsize$,$endif$$if(lang)$$lang$,$endif$$if(papersize)$$papersize$,$endif$]{$documentclass$}
|
2
|
+
\usepackage[T1]{fontenc}
|
3
|
+
\usepackage{lmodern}
|
4
|
+
\usepackage{amssymb,amsmath}
|
5
|
+
\usepackage{booktabs}
|
6
|
+
\usepackage{ifxetex,ifluatex}
|
7
|
+
\usepackage{fixltx2e} % provides \textsubscript
|
8
|
+
% use microtype if available
|
9
|
+
\IfFileExists{microtype.sty}{\usepackage{microtype}}{}
|
10
|
+
\ifnum 0\ifxetex 1\fi\ifluatex 1\fi=0 % if pdftex
|
11
|
+
\usepackage[utf8]{inputenc}
|
12
|
+
$if(euro)$
|
13
|
+
\usepackage{eurosym}
|
14
|
+
$endif$
|
15
|
+
\else % if luatex or xelatex
|
16
|
+
\usepackage{fontspec}
|
17
|
+
\ifxetex
|
18
|
+
\usepackage{xltxtra,xunicode}
|
19
|
+
\fi
|
20
|
+
\defaultfontfeatures{Mapping=tex-text,Scale=MatchLowercase}
|
21
|
+
\newcommand{\euro}{€}
|
22
|
+
$if(mainfont)$
|
23
|
+
\setmainfont{$mainfont$}
|
24
|
+
$endif$
|
25
|
+
$if(sansfont)$
|
26
|
+
\setsansfont{$sansfont$}
|
27
|
+
$endif$
|
28
|
+
$if(monofont)$
|
29
|
+
\setmonofont{$monofont$}
|
30
|
+
$endif$
|
31
|
+
$if(mathfont)$
|
32
|
+
\setmathfont{$mathfont$}
|
33
|
+
$endif$
|
34
|
+
\fi
|
35
|
+
$if(geometry)$
|
36
|
+
\usepackage[$for(geometry)$$geometry$$sep$,$endfor$]{geometry}
|
37
|
+
$else$
|
38
|
+
\usepackage[top=1in, bottom=0.8in, left=1.2in, right=1.2in]{geometry}
|
39
|
+
$endif$
|
40
|
+
$if(natbib)$
|
41
|
+
\usepackage{natbib}
|
42
|
+
\bibliographystyle{plainnat}
|
43
|
+
$endif$
|
44
|
+
$if(biblatex)$
|
45
|
+
\usepackage{biblatex}
|
46
|
+
$if(biblio-files)$
|
47
|
+
\bibliography{$biblio-files$}
|
48
|
+
$endif$
|
49
|
+
$endif$
|
50
|
+
$if(listings)$
|
51
|
+
\usepackage{listings}
|
52
|
+
$endif$
|
53
|
+
$if(lhs)$
|
54
|
+
\lstnewenvironment{code}{\lstset{language=Haskell,basicstyle=\small\ttfamily}}{}
|
55
|
+
$endif$
|
56
|
+
$if(highlighting-macros)$
|
57
|
+
$highlighting-macros$
|
58
|
+
$endif$
|
59
|
+
$if(verbatim-in-note)$
|
60
|
+
\usepackage{fancyvrb}
|
61
|
+
$endif$
|
62
|
+
$if(tables)$
|
63
|
+
\usepackage{longtable}
|
64
|
+
$endif$
|
65
|
+
$if(graphics)$
|
66
|
+
\usepackage{graphicx}
|
67
|
+
% We will generate all images so they have a width \maxwidth. This means
|
68
|
+
% that they will get their normal width if they fit onto the page, but
|
69
|
+
% are scaled down if they would overflow the margins.
|
70
|
+
\makeatletter
|
71
|
+
\def\maxwidth{\ifdim\Gin@nat@width>\linewidth\linewidth
|
72
|
+
\else\Gin@nat@width\fi}
|
73
|
+
\makeatother
|
74
|
+
\let\Oldincludegraphics\includegraphics
|
75
|
+
\renewcommand{\includegraphics}[1]{\Oldincludegraphics[width=\maxwidth]{#1}}
|
76
|
+
$endif$
|
77
|
+
\ifxetex
|
78
|
+
\usepackage[setpagesize=false, % page size defined by xetex
|
79
|
+
unicode=false, % unicode breaks when used with xetex
|
80
|
+
xetex]{hyperref}
|
81
|
+
\else
|
82
|
+
\usepackage[unicode=true]{hyperref}
|
83
|
+
\fi
|
84
|
+
\hypersetup{breaklinks=true,
|
85
|
+
bookmarks=true,
|
86
|
+
pdfauthor={$author-meta$},
|
87
|
+
pdftitle={$title-meta$},
|
88
|
+
colorlinks=true,
|
89
|
+
urlcolor=$if(urlcolor)$$urlcolor$$else$blue$endif$,
|
90
|
+
linkcolor=$if(linkcolor)$$linkcolor$$else$magenta$endif$,
|
91
|
+
pdfborder={0 0 0}}
|
92
|
+
$if(links-as-notes)$
|
93
|
+
% Make links footnotes instead of hotlinks:
|
94
|
+
\renewcommand{\href}[2]{#2\footnote{\url{#1}}}
|
95
|
+
$endif$
|
96
|
+
$if(strikeout)$
|
97
|
+
\usepackage[normalem]{ulem}
|
98
|
+
% avoid problems with \sout in headers with hyperref:
|
99
|
+
\pdfstringdefDisableCommands{\renewcommand{\sout}{}}
|
100
|
+
$endif$
|
101
|
+
\setlength{\parindent}{0pt}
|
102
|
+
\setlength{\parskip}{6pt plus 2pt minus 1pt}
|
103
|
+
\setlength{\emergencystretch}{3em} % prevent overfull lines
|
104
|
+
$if(numbersections)$
|
105
|
+
$else$
|
106
|
+
\setcounter{secnumdepth}{0}
|
107
|
+
$endif$
|
108
|
+
$if(verbatim-in-note)$
|
109
|
+
\VerbatimFootnotes % allows verbatim text in footnotes
|
110
|
+
$endif$
|
111
|
+
$if(lang)$
|
112
|
+
\ifxetex
|
113
|
+
\usepackage{polyglossia}
|
114
|
+
\setmainlanguage{$mainlang$}
|
115
|
+
\else
|
116
|
+
\usepackage[$lang$]{babel}
|
117
|
+
\fi
|
118
|
+
$endif$
|
119
|
+
$for(header-includes)$
|
120
|
+
$header-includes$
|
121
|
+
$endfor$
|
122
|
+
|
123
|
+
\newlength{\methwidth}
|
124
|
+
\setlength{\methwidth}{0.8in}
|
125
|
+
\newlength{\defnwidth}
|
126
|
+
\setlength{\defnwidth}{\textwidth}
|
127
|
+
\addtolength{\defnwidth}{-2.0in}
|
128
|
+
\newlength{\returnwidth}
|
129
|
+
\setlength{\returnwidth}{0.8in}
|
130
|
+
\def\qquad{\quad\quad}
|
131
|
+
\def\qqqquad{\quad\quad\quad\quad}
|
132
|
+
|
133
|
+
$if(title)$
|
134
|
+
\title{$title$}
|
135
|
+
$endif$
|
136
|
+
\author{$for(author)$$author$$sep$ \and $endfor$}
|
137
|
+
\date{$date$}
|
138
|
+
|
139
|
+
\begin{document}
|
140
|
+
$if(title)$
|
141
|
+
\maketitle
|
142
|
+
$endif$
|
143
|
+
|
144
|
+
$for(include-before)$
|
145
|
+
$include-before$
|
146
|
+
|
147
|
+
$endfor$
|
148
|
+
$if(toc)$
|
149
|
+
{
|
150
|
+
\hypersetup{linkcolor=black}
|
151
|
+
\tableofcontents
|
152
|
+
}
|
153
|
+
$endif$
|
154
|
+
$body$
|
155
|
+
|
156
|
+
$if(natbib)$
|
157
|
+
$if(biblio-files)$
|
158
|
+
$if(biblio-title)$
|
159
|
+
$if(book-class)$
|
160
|
+
\renewcommand\bibname{$biblio-title$}
|
161
|
+
$else$
|
162
|
+
\renewcommand\refname{$biblio-title$}
|
163
|
+
$endif$
|
164
|
+
$endif$
|
165
|
+
\bibliography{$biblio-files$}
|
166
|
+
|
167
|
+
$endif$
|
168
|
+
$endif$
|
169
|
+
$if(biblatex)$
|
170
|
+
\printbibliography$if(biblio-title)$[title=$biblio-title$]$endif$
|
171
|
+
|
172
|
+
$endif$
|
173
|
+
$for(include-after)$
|
174
|
+
$include-after$
|
175
|
+
|
176
|
+
$endfor$
|
177
|
+
\end{document}
|
data/spec/acos_spec.rb
ADDED
@@ -0,0 +1,66 @@
|
|
1
|
+
require File.join(File.dirname(__FILE__), 'spec_helper')
|
2
|
+
|
3
|
+
# All tests adapted from MPC 1.0.1's tests/acos.dat
|
4
|
+
describe MPC, '#acos' do
|
5
|
+
it 'should calculate the inverse cosine of a pure real argument' do
|
6
|
+
data = [
|
7
|
+
[[ "0x1921FB54442D18p-51", 53, 16], [ "0x13D2B7539DBA4Cp-51", 53, 16], MPC.new([GMP::F(-6 ), -GMP::F(0)])],
|
8
|
+
[[ "0x1921FB54442D18p-51", 53, 16], ["-0x13D2B7539DBA4Cp-51", 53, 16], MPC.new([GMP::F(-6 ), GMP::F(0)])],
|
9
|
+
[[ "0x1921FB54442D18p-51", 53, 16], [ "0x15124271980435p-52", 53, 16], MPC.new([GMP::F(-2 ), -GMP::F(0)])],
|
10
|
+
[[ "0x1921FB54442D18p-51", 53, 16], ["-0x15124271980435p-52", 53, 16], MPC.new([GMP::F(-2 ), GMP::F(0)])],
|
11
|
+
[[ "0x1921FB54442D18p-51", 53, 16], [0], MPC.new([GMP::F(-1 ), -GMP::F(0)])],
|
12
|
+
[[ "0x1921FB54442D18p-51", 53, 16], [0], MPC.new([GMP::F(-1 ), GMP::F(0)])],
|
13
|
+
[[ "0x10C152382D7366p-51", 53, 16], [0], MPC.new([GMP::F(-0.5), -GMP::F(0)])],
|
14
|
+
[[ "0x10C152382D7366p-51", 53, 16], [0], MPC.new([GMP::F(-0.5), GMP::F(0)])],
|
15
|
+
[[ "0x10C152382D7366p-52", 53, 16], [0], MPC.new([GMP::F( 0.5), GMP::F(0)])],
|
16
|
+
[[ "0x10C152382D7366p-52", 53, 16], [0], MPC.new([GMP::F( 0.5), -GMP::F(0)])],
|
17
|
+
[[0], [0], MPC.new([GMP::F( 1 ), GMP::F(0)])],
|
18
|
+
[[0], [0], MPC.new([GMP::F( 1 ), -GMP::F(0)])],
|
19
|
+
[[0], ["-0x15124271980435p-52", 53, 16], MPC.new([GMP::F( 2 ), GMP::F(0)])],
|
20
|
+
[[0], [ "0x15124271980435p-52", 53, 16], MPC.new([GMP::F( 2 ), -GMP::F(0)])],
|
21
|
+
[[0], ["-0x13D2B7539DBA4Cp-51", 53, 16], MPC.new([GMP::F( 6 ), GMP::F(0)])],
|
22
|
+
[[0], [ "0x13D2B7539DBA4Cp-51", 53, 16], MPC.new([GMP::F( 6 ), -GMP::F(0)])]
|
23
|
+
]
|
24
|
+
data.each do |expected_real, expected_imag, input|
|
25
|
+
actual = input.acos
|
26
|
+
actual.real.should eq GMP::F.new(*expected_real)
|
27
|
+
actual.imag.should eq GMP::F.new(*expected_imag)
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
it 'should calculate the inverse cosine of a pure imaginary argument' do
|
32
|
+
data = [
|
33
|
+
[["0x1921FB54442D18p-52", 53, 16], [ "0x1D185B507EDC0Ep-52", 53, 16], MPC.new([-GMP::F(0), GMP::F(-3 )])],
|
34
|
+
[["0x1921FB54442D18p-52", 53, 16], [ "0x1D185B507EDC0Ep-52", 53, 16], MPC.new([ GMP::F(0), GMP::F(-3 )])],
|
35
|
+
[["0x1921FB54442D18p-52", 53, 16], [ "0x1FACFB2399E637p-55", 53, 16], MPC.new([-GMP::F(0), GMP::F(-0.25)])],
|
36
|
+
[["0x1921FB54442D18p-52", 53, 16], [ "0x1FACFB2399E637p-55", 53, 16], MPC.new([ GMP::F(0), GMP::F(-0.25)])],
|
37
|
+
[["0x1921FB54442D18p-52", 53, 16], ["-0x1FACFB2399E637p-55", 53, 16], MPC.new([-GMP::F(0), GMP::F( 0.25)])],
|
38
|
+
[["0x1921FB54442D18p-52", 53, 16], ["-0x1FACFB2399E637p-55", 53, 16], MPC.new([ GMP::F(0), GMP::F( 0.25)])],
|
39
|
+
[["0x1921FB54442D18p-52", 53, 16], ["-0x1D185B507EDC0Ep-52", 53, 16], MPC.new([-GMP::F(0), GMP::F( 3 )])],
|
40
|
+
[["0x1921FB54442D18p-52", 53, 16], ["-0x1D185B507EDC0Ep-52", 53, 16], MPC.new([ GMP::F(0), GMP::F( 3 )])],
|
41
|
+
]
|
42
|
+
data.each do |expected_real, expected_imag, input|
|
43
|
+
actual = input.acos
|
44
|
+
actual.real.should eq GMP::F.new(*expected_real)
|
45
|
+
actual.imag.should eq GMP::F.new(*expected_imag)
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
it 'should calculate the inverse cosine with other precisions' do
|
50
|
+
actual = MPC.new([GMP::F.new(2), GMP::F.new(1)]).acos(MPC::MPC_RNDNZ, 2)
|
51
|
+
actual.real.should eq GMP::F.new( 0.5, 2)
|
52
|
+
actual.imag.should eq GMP::F.new(-1, 2)
|
53
|
+
end
|
54
|
+
|
55
|
+
it 'should calculate the inverse cosine with other precisions' do
|
56
|
+
actual = MPC.new([GMP::F.new(8.5), GMP::F.new(-71)]).acos(MPC::MPC_RNDNU, 9)
|
57
|
+
actual.real.should eq GMP::F.new("0x5Dp-6", 9, 16)
|
58
|
+
actual.imag.should eq GMP::F.new("0x9Fp-5", 9, 16)
|
59
|
+
end
|
60
|
+
|
61
|
+
it 'should calculate the inverse cosine with other precisions' do
|
62
|
+
actual = MPC.new([GMP::F.new("0x3243F6A8885A3p-48", 53, 16), GMP::F.new("0x162E42FEFA39EFp-53", 53, 16)]).acos
|
63
|
+
actual.real.should eq GMP::F.new("0x74C141310E695p-53", 53, 16)
|
64
|
+
actual.imag.should eq GMP::F.new("-0x1D6D2CFA9F3F11p-52", 53, 16)
|
65
|
+
end
|
66
|
+
end
|
@@ -0,0 +1,51 @@
|
|
1
|
+
require File.join(File.dirname(__FILE__), 'spec_helper')
|
2
|
+
|
3
|
+
describe MPC, '#add' do
|
4
|
+
it 'should calculate the sum of an MPC and a Fixnum' do
|
5
|
+
op1 = MPC.new([7, 16])
|
6
|
+
actual = op1.add(0)
|
7
|
+
actual.real.should eq 7
|
8
|
+
actual.imag.should eq 16
|
9
|
+
|
10
|
+
actual = op1.add(6)
|
11
|
+
actual.real.should eq 13
|
12
|
+
actual.imag.should eq 16
|
13
|
+
|
14
|
+
actual = op1.add(-1000)
|
15
|
+
actual.real.should eq -993
|
16
|
+
actual.imag.should eq 16
|
17
|
+
|
18
|
+
op1 = MPC.new([GMP::F(3.1), GMP::F(16)])
|
19
|
+
actual = op1.add(3)
|
20
|
+
actual.real.should eq GMP::F(6.1)
|
21
|
+
actual.imag.should eq 16
|
22
|
+
end
|
23
|
+
|
24
|
+
it 'should calculate the sum of an MPC and a GMP::Z' do
|
25
|
+
op1 = MPC.new([7, 16])
|
26
|
+
actual = op1.add(GMP::Z(0))
|
27
|
+
actual.real.should eq 7
|
28
|
+
actual.imag.should eq 16
|
29
|
+
|
30
|
+
actual = op1.add(GMP::Z(-1000))
|
31
|
+
actual.real.should eq -993
|
32
|
+
actual.imag.should eq 16
|
33
|
+
|
34
|
+
op1 = MPC.new([GMP::F(3.1), GMP::F(16)])
|
35
|
+
actual = op1.add(GMP::Z(3))
|
36
|
+
actual.real.should eq GMP::F(6.1)
|
37
|
+
actual.imag.should eq 16
|
38
|
+
end
|
39
|
+
|
40
|
+
it 'should calculate the sum of an MPC and a Bignum' do
|
41
|
+
op1 = MPC.new([7, 16])
|
42
|
+
actual = op1.add(2**65) # 36893488147419103232
|
43
|
+
actual.real.should eq 36893488147419103239
|
44
|
+
actual.imag.should eq 16
|
45
|
+
|
46
|
+
op1 = MPC.new([GMP::F(3.1), GMP::F(16)])
|
47
|
+
actual = op1.add(2**65) # 36893488147419103232
|
48
|
+
actual.real.should eq GMP::F("36893488147419103235.1")
|
49
|
+
actual.imag.should eq 16
|
50
|
+
end
|
51
|
+
end
|
data/spec/add_fr_spec.rb
ADDED
@@ -0,0 +1,54 @@
|
|
1
|
+
require File.join(File.dirname(__FILE__), 'spec_helper')
|
2
|
+
|
3
|
+
# All tests adapted from MPC 1.0.1's tests/add.dat
|
4
|
+
describe MPC, '#add' do
|
5
|
+
it 'should calculate the sum of two real MPCs' do
|
6
|
+
op1 = MPC.new([1, 0])
|
7
|
+
op2_106 = GMP::F("0x10000000000001p-106", 53, 16)
|
8
|
+
actual = op1.add(op2_106, MPC::MPC_RNDNN)
|
9
|
+
actual.real.should eq GMP::F("0x10000000000000p-52", 53, 16)
|
10
|
+
actual.imag.should eq GMP::F(0)
|
11
|
+
|
12
|
+
op2_105 = GMP::F("0x10000000000001p-105", 53, 16)
|
13
|
+
actual = op1.add(op2_105, MPC::MPC_RNDNN)
|
14
|
+
actual.real.should eq GMP::F("0x10000000000001p-52", 53, 16)
|
15
|
+
actual.imag.should eq GMP::F(0)
|
16
|
+
|
17
|
+
op2_104 = GMP::F("0x10000000000001p-104", 53, 16)
|
18
|
+
actual = op1.add(op2_104, MPC::MPC_RNDNN)
|
19
|
+
actual.real.should eq GMP::F("0x10000000000001p-52", 53, 16)
|
20
|
+
actual.imag.should eq GMP::F(0)
|
21
|
+
|
22
|
+
actual = op1.add(op2_105, MPC::MPC_RNDZZ)
|
23
|
+
actual.real.should eq GMP::F("0x10000000000000p-52", 53, 16)
|
24
|
+
actual.imag.should eq GMP::F(0)
|
25
|
+
|
26
|
+
actual = op1.add(op2_105, MPC::MPC_RNDUU)
|
27
|
+
actual.real.should eq GMP::F("0x10000000000001p-52", 53, 16)
|
28
|
+
actual.imag.should eq GMP::F(0)
|
29
|
+
|
30
|
+
actual = op1.add(op2_105, MPC::MPC_RNDDD)
|
31
|
+
actual.real.should eq GMP::F("0x10000000000000p-52", 53, 16)
|
32
|
+
actual.imag.should eq GMP::F(0)
|
33
|
+
end
|
34
|
+
|
35
|
+
it 'should calculate the sum of an imaginary argument with a complex one.' do
|
36
|
+
op1 = MPC.new([0, 1])
|
37
|
+
op2 = GMP::F(1)
|
38
|
+
actual = op1.add(op2, MPC::MPC_RNDNN)
|
39
|
+
actual.real.should eq GMP::F(1)
|
40
|
+
actual.imag.should eq GMP::F(1)
|
41
|
+
|
42
|
+
actual = op1.add(op2, MPC::MPC_RNDZZ)
|
43
|
+
actual.real.should eq GMP::F(1)
|
44
|
+
actual.imag.should eq GMP::F(1)
|
45
|
+
|
46
|
+
actual = op1.add(op2, MPC::MPC_RNDUU)
|
47
|
+
actual.real.should eq GMP::F(1)
|
48
|
+
actual.imag.should eq GMP::F(1)
|
49
|
+
|
50
|
+
actual = op1.add(op2, MPC::MPC_RNDDD)
|
51
|
+
actual.real.should eq GMP::F(1)
|
52
|
+
actual.imag.should eq GMP::F(1)
|
53
|
+
end
|
54
|
+
end
|
data/spec/add_spec.rb
ADDED
@@ -0,0 +1,32 @@
|
|
1
|
+
require File.join(File.dirname(__FILE__), 'spec_helper')
|
2
|
+
|
3
|
+
# All tests adapted from MPC 1.0.1's tests/add.dat
|
4
|
+
describe MPC, '#add' do
|
5
|
+
it 'should calculate the sum of two real MPCs' do
|
6
|
+
op1 = MPC.new([1, 0])
|
7
|
+
op2 = MPC.new([GMP::F("0x10000000000001p-105", 53, 16), GMP::F(0)])
|
8
|
+
actual = op1.add(op2, MPC::MPC_RNDNN)
|
9
|
+
actual.real.should eq GMP::F("0x10000000000001p-52", 53, 16)
|
10
|
+
actual.imag.should eq GMP::F(0)
|
11
|
+
|
12
|
+
actual = op1.add(op2, MPC::MPC_RNDZZ)
|
13
|
+
actual.real.should eq GMP::F("0x10000000000000p-52", 53, 16)
|
14
|
+
actual.imag.should eq GMP::F(0)
|
15
|
+
|
16
|
+
actual = op1.add(op2, MPC::MPC_RNDUU)
|
17
|
+
actual.real.should eq GMP::F("0x10000000000001p-52", 53, 16)
|
18
|
+
actual.imag.should eq GMP::F(0)
|
19
|
+
|
20
|
+
actual = op1.add(op2, MPC::MPC_RNDDD)
|
21
|
+
actual.real.should eq GMP::F("0x10000000000000p-52", 53, 16)
|
22
|
+
actual.imag.should eq GMP::F(0)
|
23
|
+
end
|
24
|
+
|
25
|
+
it 'should calculate the sum of two real MPCs' do
|
26
|
+
op2 = MPC.new([GMP::F(0), GMP::F("0x10000000000001p-105", 53, 16)])
|
27
|
+
op1 = MPC.new([0, 1])
|
28
|
+
actual = op1.add(op2, MPC::MPC_RNDNN)
|
29
|
+
actual.real.should eq GMP::F(0)
|
30
|
+
actual.imag.should eq GMP::F("0x10000000000001p-52", 53, 16)
|
31
|
+
end
|
32
|
+
end
|
data/spec/asin_spec.rb
ADDED
@@ -0,0 +1,66 @@
|
|
1
|
+
require File.join(File.dirname(__FILE__), 'spec_helper')
|
2
|
+
|
3
|
+
# All tests adapted from MPC 1.0.1's tests/asin.dat
|
4
|
+
describe MPC, '#sin' do
|
5
|
+
it 'should calculate the inverse sine of a pure real argument' do
|
6
|
+
data = [
|
7
|
+
[["-0x1921FB54442D18p-52", 53, 16], ["-0x1ECC2CAEC5160Ap-53", 53, 16], MPC.new([GMP::F(-1.5), -GMP::F(0)])],
|
8
|
+
[["-0x1921FB54442D18p-52", 53, 16], [ "0x1ECC2CAEC5160Ap-53", 53, 16], MPC.new([GMP::F(-1.5), GMP::F(0)])],
|
9
|
+
[["-0x1921FB54442D18p-52", 53, 16], [0], MPC.new([GMP::F(-1 ), -GMP::F(0)])],
|
10
|
+
[["-0x1921FB54442D18p-52", 53, 16], [0], MPC.new([GMP::F(-1 ), GMP::F(0)])],
|
11
|
+
[["-0x10C152382D7366p-53", 53, 16], [0], MPC.new([GMP::F(-0.5), -GMP::F(0)])],
|
12
|
+
[["-0x10C152382D7366p-53", 53, 16], [0], MPC.new([GMP::F(-0.5), GMP::F(0)])],
|
13
|
+
[[ "0x10C152382D7366p-53", 53, 16], [0], MPC.new([GMP::F( 0.5), -GMP::F(0)])],
|
14
|
+
[[ "0x10C152382D7366p-53", 53, 16], [0], MPC.new([GMP::F( 0.5), GMP::F(0)])],
|
15
|
+
[[ "0x1921FB54442D18p-52", 53, 16], [0], MPC.new([GMP::F( 1 ), -GMP::F(0)])],
|
16
|
+
[[ "0x1921FB54442D18p-52", 53, 16], [0], MPC.new([GMP::F( 1 ), GMP::F(0)])],
|
17
|
+
[[ "0x1921FB54442D18p-52", 53, 16], ["-0x1ECC2CAEC5160Ap-53", 53, 16], MPC.new([GMP::F( 1.5), -GMP::F(0)])],
|
18
|
+
[[ "0x1921FB54442D18p-52", 53, 16], [ "0x1ECC2CAEC5160Ap-53", 53, 16], MPC.new([GMP::F( 1.5), GMP::F(0)])]
|
19
|
+
]
|
20
|
+
data.each do |expected_real, expected_imag, input|
|
21
|
+
actual = input.asin
|
22
|
+
actual.real.should eq GMP::F.new(*expected_real)
|
23
|
+
actual.imag.should eq GMP::F.new(*expected_imag)
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
it 'should calculate the inverse sine of a pure imaginary argument' do
|
28
|
+
data = [
|
29
|
+
[[-GMP::F(0)], ["-0x131DC0090B63D8p-52", 53, 16], MPC.new([-GMP::F(0), GMP::F(-1.5)])],
|
30
|
+
[[ GMP::F(0)], ["-0x131DC0090B63D8p-52", 53, 16], MPC.new([ GMP::F(0), GMP::F(-1.5)])],
|
31
|
+
[[-GMP::F(0)], ["-0x1C34366179D427p-53", 53, 16], MPC.new([-GMP::F(0), GMP::F(-1 )])],
|
32
|
+
[[ GMP::F(0)], ["-0x1C34366179D427p-53", 53, 16], MPC.new([ GMP::F(0), GMP::F(-1 )])],
|
33
|
+
[[-GMP::F(0)], ["-0x1ECC2CAEC5160Ap-54", 53, 16], MPC.new([-GMP::F(0), GMP::F(-0.5)])],
|
34
|
+
[[ GMP::F(0)], ["-0x1ECC2CAEC5160Ap-54", 53, 16], MPC.new([ GMP::F(0), GMP::F(-0.5)])],
|
35
|
+
[[-GMP::F(0)], [ "0x1ECC2CAEC5160Ap-54", 53, 16], MPC.new([-GMP::F(0), GMP::F( 0.5)])],
|
36
|
+
[[ GMP::F(0)], [ "0x1ECC2CAEC5160Ap-54", 53, 16], MPC.new([ GMP::F(0), GMP::F( 0.5)])],
|
37
|
+
[[-GMP::F(0)], [ "0x1C34366179D427p-53", 53, 16], MPC.new([-GMP::F(0), GMP::F( 1 )])],
|
38
|
+
[[ GMP::F(0)], [ "0x1C34366179D427p-53", 53, 16], MPC.new([ GMP::F(0), GMP::F( 1 )])],
|
39
|
+
[[-GMP::F(0)], [ "0x131DC0090B63D8p-52", 53, 16], MPC.new([-GMP::F(0), GMP::F( 1.5)])],
|
40
|
+
[[ GMP::F(0)], [ "0x131DC0090B63D8p-52", 53, 16], MPC.new([ GMP::F(0), GMP::F( 1.5)])]
|
41
|
+
]
|
42
|
+
data.each do |expected_real, expected_imag, input|
|
43
|
+
actual = input.asin
|
44
|
+
actual.real.should eq GMP::F.new(*expected_real)
|
45
|
+
actual.imag.should eq GMP::F.new(*expected_imag)
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
it 'should calculate the inverse sine of ieee-754 double precision numbers' do
|
50
|
+
actual = MPC.new([GMP::F.new(17), GMP::F.new(42)]).asin(MPC::MPC_RNDNN)
|
51
|
+
actual.real.should eq GMP::F.new("0x189BF9EC7FCD5Bp-54", 53, 16)
|
52
|
+
actual.imag.should eq GMP::F.new("0x1206ECFA94614Bp-50", 53, 16)
|
53
|
+
end
|
54
|
+
|
55
|
+
it 'should calculate the inverse sine with other precisions' do
|
56
|
+
actual = MPC.new([GMP::F.new(96), GMP::F.new("0x1p-8", 2, 16)]).asin(MPC::MPC_RNDNN, 2)
|
57
|
+
actual.real.should eq GMP::F.new(1.5, 2)
|
58
|
+
actual.imag.should eq GMP::F.new(6, 2)
|
59
|
+
end
|
60
|
+
|
61
|
+
it 'should calculate the inverse sine with other precisions' do
|
62
|
+
actual = MPC.new([GMP::F.new(96), GMP::F.new("0x1p-8", 2, 16)]).asin(MPC::MPC_RNDNN, 8)
|
63
|
+
actual.real.should eq GMP::F.new("0xC9p-7", 8, 16)
|
64
|
+
actual.imag.should eq GMP::F.new("0x15p-2", 8, 16)
|
65
|
+
end
|
66
|
+
end
|