-
Notifications
You must be signed in to change notification settings - Fork 14
Expand file tree
/
Copy patharithmetic.xml
More file actions
105 lines (103 loc) · 3.1 KB
/
arithmetic.xml
File metadata and controls
105 lines (103 loc) · 3.1 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
<?xml version="1.0" encoding="utf-8"?>
<!-- EN-Revision: 52407313885d27a4e891e08dd2e2481bcc39e244 Maintainer: pastore Status: ready -->
<!-- CREDITS: cucinato -->
<sect1 xml:id="language.operators.arithmetic">
<title>Operatori aritmetici</title>
<simpara>
Ricordate l'aritmetica di base dalla scuola? Questi operatori funzionano esattamente
nello stesso modo.
</simpara>
<table>
<title>Operatori aritmetici</title>
<tgroup cols="3">
<thead>
<row>
<entry>Esempio</entry>
<entry>Nome</entry>
<entry>Risultato</entry>
</row>
</thead>
<tbody>
<row>
<entry>+$a</entry>
<entry>Identità</entry>
<entry>
Conversione di <varname>$a</varname> in <type>int</type> o
<type>float</type> in modo appropriato.
</entry>
</row>
<row>
<entry>-$a</entry>
<entry>Negazione</entry>
<entry>Opposto di <varname>$a</varname>.</entry>
</row>
<row>
<entry>$a + $b</entry>
<entry>Addizione</entry>
<entry>La somma di <varname>$a</varname> e <varname>$b</varname>.</entry>
</row>
<row>
<entry>$a - $b</entry>
<entry>Sottrazione</entry>
<entry>La differenza di <varname>$a</varname> e <varname>$b</varname>.</entry>
</row>
<row>
<entry>$a * $b</entry>
<entry>Moltiplicazione</entry>
<entry>il prodotto di <varname>$a</varname> e <varname>$b</varname>.</entry>
</row>
<row>
<entry>$a / $b</entry>
<entry>Divisione</entry>
<entry>Quoziente di <varname>$a</varname> e <varname>$b</varname>.</entry>
</row>
<row>
<entry>$a % $b</entry>
<entry>Modulo</entry>
<entry>Il resto di <varname>$a</varname> diviso da <varname>$b</varname>.</entry>
</row>
<row>
<entry>$a ** $b</entry>
<entry>Elevamento a potenza</entry>
<entry>Risultato di elevazione <varname>$a</varname> alla <varname>$b</varname>esima potenza.</entry>
</row>
</tbody>
</tgroup>
</table>
<simpara>
L'operatore di divisione ("/") restituisce un valore float a meno che i due operandi
siano interi (oppure stringhe che vengono convertite in interi) e i numeri
siano divisibili, nel qual caso viene restituito un valore intero. Per le
divisioni di interi, vedere <function>intdiv</function>.
</simpara>
<simpara>
Gli operandi del modulo sono convertiti in <type>int</type>
prima dell'operazione. Per il modulo di numeri a virgola mobile, vedere
<function>fmod</function>.
</simpara>
<para>
Il risultato dell'operatore modulo <literal>%</literal> ha lo stesso segno
del dividendo - ovvero, il risultato di <literal>$a % $b</literal>
avrà lo stesso segno di <varname>$a</varname>. Per esempio:
<informalexample>
<programlisting role="php">
<![CDATA[
<?php
echo (5 % 3)."\n"; // prints 2
echo (5 % -3)."\n"; // prints 2
echo (-5 % 3)."\n"; // prints -2
echo (-5 % -3)."\n"; // prints -2
?>
]]>
</programlisting>
</informalexample>
</para>
<sect2 role="seealso">
&reftitle.seealso;
<para>
<simplelist>
<member><link linkend="ref.math">Funzioni matematiche</link></member>
</simplelist>
</para>
</sect2>
</sect1>