2 <link rel=
"stylesheet" href=
"style.css" type=
"text/css">
3 <meta content=
"text/html; charset=iso-8859-1" http-equiv=
"Content-Type">
4 <link rel=
"Start" href=
"index.html">
5 <link title=
"Index of types" rel=Appendix
href=
"index_types.html">
6 <link title=
"Index of exceptions" rel=Appendix
href=
"index_exceptions.html">
7 <link title=
"Index of values" rel=Appendix
href=
"index_values.html">
8 <link title=
"Index of modules" rel=Appendix
href=
"index_modules.html">
9 <link title=
"Types" rel=
"Chapter" href=
"Types.html">
10 <link title=
"Parser" rel=
"Chapter" href=
"Parser.html">
11 <link title=
"Lexer" rel=
"Chapter" href=
"Lexer.html">
12 <link title=
"Value" rel=
"Chapter" href=
"Value.html">
13 <link title=
"Signal" rel=
"Chapter" href=
"Signal.html">
14 <link title=
"Faustexp" rel=
"Chapter" href=
"Faustexp.html">
15 <link title=
"Interpreter" rel=
"Chapter" href=
"Interpreter.html">
16 <link title=
"Preprocess" rel=
"Chapter" href=
"Preprocess.html">
17 <link title=
"Main" rel=
"Chapter" href=
"Main.html"><title>Value.v_add
</title>
20 <code class=
"code"><span class=
"keyword">let
</span> <span class=
"keyword">rec
</span> v_add
v1
v2
=
<span class=
"keyword">match
</span> v1
<span class=
"keyword">with
</span><br>
21 <span class=
"keywordsign">|
</span><span class=
"constructor">Vec
</span> (size1,
vec1)
<span class=
"keywordsign">-
></span> <br>
22 (
<br>
23 <span class=
"keyword">match
</span> v2
<span class=
"keyword">with
</span><br>
24 <span class=
"keywordsign">|
</span><span class=
"constructor">Vec
</span> (size2,
vec2)
<span class=
"keywordsign">-
></span> <br>
25 <span class=
"keyword">if
</span> size1
=
size2
<span class=
"keyword">then
</span> <br>
26 make_vector
size1
(
<span class=
"keyword">fun
</span> i
<span class=
"keywordsign">-
></span> v_add
(vec1
i)
(vec2
i))
<br>
27 <span class=
"keyword">else
</span> raise
(
<span class=
"constructor">Value_operation
</span> <span class=
"string">"vector size not matched."</span>)
<br>
28 <span class=
"keywordsign">|
</span><span class=
"constructor">Zero
</span> <span class=
"keywordsign">-
></span> v1
<br>
29 <span class=
"keywordsign">|
</span>_
<span class=
"keywordsign">-
></span> raise
(
<span class=
"constructor">Value_operation
</span> <span class=
"string">"Vector_Scalar vec1 +~ sca2"</span>)
<br>
30 )
<br>
31 <span class=
"keywordsign">|
</span><span class=
"constructor">N
</span> i1
<span class=
"keywordsign">-
></span><br>
32 (
<br>
33 <span class=
"keyword">match
</span> v2
<span class=
"keyword">with
</span><br>
34 <span class=
"keywordsign">|
</span><span class=
"constructor">N
</span> i2
<span class=
"keywordsign">-
></span> normalize
(return_N
(i1
+
i2))
<br>
35 <span class=
"keywordsign">|
</span><span class=
"constructor">R
</span> f2
<span class=
"keywordsign">-
></span> normalize
(return_R
((float_of_int
i1)
+.
f2))
<br>
36 <span class=
"keywordsign">|
</span><span class=
"constructor">Vec
</span> (size2,
vec2)
<span class=
"keywordsign">-
></span> raise
(
<span class=
"constructor">Value_operation
</span> <span class=
"string">"Vector_Scalar i1 +~ vec2"</span>)
<br>
37 <span class=
"keywordsign">|
</span><span class=
"constructor">Zero
</span> <span class=
"keywordsign">-
></span> v1
<br>
38 <span class=
"keywordsign">|
</span><span class=
"constructor">W
</span> <span class=
"keywordsign">-
></span> fail
<br>
39 )
<br>
40 <span class=
"keywordsign">|
</span><span class=
"constructor">R
</span> f1
<span class=
"keywordsign">-
></span><br>
41 (
<br>
42 <span class=
"keyword">match
</span> v2
<span class=
"keyword">with
</span><br>
43 <span class=
"keywordsign">|
</span><span class=
"constructor">N
</span> i2
<span class=
"keywordsign">-
></span> normalize
(return_R
(f1
+.
(float_of_int
i2)))
<br>
44 <span class=
"keywordsign">|
</span><span class=
"constructor">R
</span> f2
<span class=
"keywordsign">-
></span> normalize
(return_R
(f1
+.
f2))
<br>
45 <span class=
"keywordsign">|
</span><span class=
"constructor">Vec
</span> (size2,
vec2)
<span class=
"keywordsign">-
></span> raise
(
<span class=
"constructor">Value_operation
</span> <span class=
"string">"Vector_Scalar f1 +~ vec2"</span>)
<br>
46 <span class=
"keywordsign">|
</span><span class=
"constructor">Zero
</span> <span class=
"keywordsign">-
></span> v1
<br>
47 <span class=
"keywordsign">|
</span><span class=
"constructor">W
</span> <span class=
"keywordsign">-
></span> fail
<br>
48 )
<br>
49 <span class=
"keywordsign">|
</span><span class=
"constructor">Zero
</span> <span class=
"keywordsign">-
></span> v2
<br>
50 <span class=
"keywordsign">|
</span><span class=
"constructor">W
</span> <span class=
"keywordsign">-
></span><br>
51 (
<br>
52 <span class=
"keyword">match
</span> v2
<span class=
"keyword">with
</span><br>
53 <span class=
"keywordsign">|
</span><span class=
"constructor">N
</span> i2
<span class=
"keywordsign">-
></span> fail
<br>
54 <span class=
"keywordsign">|
</span><span class=
"constructor">R
</span> f2
<span class=
"keywordsign">-
></span> fail
<br>
55 <span class=
"keywordsign">|
</span><span class=
"constructor">Vec
</span> (size2,
vec2)
<span class=
"keywordsign">-
></span> raise
(
<span class=
"constructor">Value_operation
</span> <span class=
"string">"Vector_Scalar W +~ vec2"</span>)
<br>
56 <span class=
"keywordsign">|
</span><span class=
"constructor">Zero
</span> <span class=
"keywordsign">-
></span> v1
<br>
57 <span class=
"keywordsign">|
</span><span class=
"constructor">W
</span> <span class=
"keywordsign">-
></span> fail
<br>
58 )
</code></body></html>