-
Notifications
You must be signed in to change notification settings - Fork 50
Expand file tree
/
Copy patharithmetic.xml
More file actions
119 lines (119 loc) · 3.51 KB
/
arithmetic.xml
File metadata and controls
119 lines (119 loc) · 3.51 KB
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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
<?xml version="1.0" encoding="utf-8"?>
<!-- EN-Revision: 16934048f79c6e117cd16a23c09c1b2ea502e284 Maintainer: nobody Status: ready -->
<!-- Reviewed: yes -->
<!-- Rev-Revision: e4b889a3e8b9d87ab605aac9bbe85d2c16c69a1b Reviewer: samesch -->
<!-- CREDITS: tzwenny, betz -->
<sect1 xml:id="language.operators.arithmetic">
<title>Arithmetische Operatoren</title>
<titleabbrev>Arithmetisch</titleabbrev>
<simpara>
Erinnern Sie sich noch an die Grundrechenarten aus der Schule? Die
arithmetischen Operatoren funktionieren genauso:
</simpara>
<table>
<title>Arithmetische Operatoren</title>
<tgroup cols="3">
<thead>
<row>
<entry>Beispiel</entry>
<entry>Name</entry>
<entry>Ergebnis</entry>
</row>
</thead>
<tbody>
<row>
<entry><code>+$a</code></entry>
<entry>Identity</entry>
<entry>
Umwandlung von <varname>$a</varname> nach <type>int</type> oder
<type>float</type> je nach Bedarf.
</entry>
</row>
<row>
<entry><code>-$a</code></entry>
<entry>Negation</entry>
<entry>Gegenzahl von <varname>$a</varname>.</entry>
</row>
<row>
<entry><code>$a + $b</code></entry>
<entry>Addition</entry>
<entry>Summe von <varname>$a</varname> und <varname>$b</varname>.</entry>
</row>
<row>
<entry><code>$a - $b</code></entry>
<entry>Subtraktion</entry>
<entry>Differenz von <varname>$a</varname> und <varname>$b</varname>.</entry>
</row>
<row>
<entry><code>$a * $b</code></entry>
<entry>Multiplikation</entry>
<entry>Produkt von <varname>$a</varname> und <varname>$b</varname>.</entry>
</row>
<row>
<entry><code>$a / $b</code></entry>
<entry>Division</entry>
<entry>Quotient von <varname>$a</varname> und <varname>$b</varname>.</entry>
</row>
<row>
<entry><code>$a % $b</code></entry>
<entry>Modulus</entry>
<entry>Rest von <varname>$a</varname> geteilt durch <varname>$b</varname>.</entry>
</row>
<row>
<entry><code>$a ** $b</code></entry>
<entry>Potenz</entry>
<entry><varname>$b</varname>-te Potenz von <varname>$a</varname>.</entry>
</row>
</tbody>
</tgroup>
</table>
<simpara>
Der Divisions-Operator <literal>/</literal> gibt einen Wert vom Typ
<type>float</type> zurück, es sei denn beide Operanden sind vom Typ
<type>int</type> (oder
<link linkend="language.types.numeric-strings">numerische Zeichenketten</link>
die in <type>int</type> umgewandelt werden) und der Zähler ist ein Vielfaches
des Nenners; in diesem Fall wird eine Ganzzahl zurückgegeben.
Für Ganzzahldivision siehe <function>intdiv</function>.
</simpara>
<simpara>
Operanden des Modulus-Operators werden vor der Verarbeitung in
<type>int</type> umgewandelt. Für den Gleitkommazahlen-Modulus ist
<function>fmod</function> verfügbar.
</simpara>
<para>
Das Ergebnis des Modulus-Operators <literal>%</literal> hat dasselbe
Vorzeichen wie der Dividend, &dh; das Ergebnis von <code>$a % $b</code>
hat dasselbe Vorzeichen wie <varname>$a</varname>. Zum Beispiel:
<example>
<title>Der Modulus-Operator</title>
<programlisting role="php">
<![CDATA[
<?php
var_dump(5 % 3);
var_dump(5 % -3);
var_dump(-5 % 3);
var_dump(-5 % -3);
?>
]]>
</programlisting>
&example.outputs;
<screen>
<![CDATA[
int(2)
int(2)
int(-2)
int(-2)
]]>
</screen>
</example>
</para>
<sect2 role="seealso">
&reftitle.seealso;
<para>
<simplelist>
<member><link linkend="ref.math">Mathematische Funktionen</link></member>
</simplelist>
</para>
</sect2>
</sect1>