## Julia – 10 – operazioni matematiche e funzioni elementari – 1 Continuo da qui, copio qui.

Julia provides a complete collection of basic arithmetic and bitwise operators across all of its numeric primitive types, as well as providing portable, efficient implementations of a comprehensive collection of standard mathematical functions.

Operatori aritmetici
The following arithmetic operators are supported on all primitive numeric types:

``````Expr. Name           Description
+x    unary plus     the identity operation
-x    unary minus    maps values to their additive inverses
x + y binary plus    performs addition
x - y binary minus   performs subtraction
x * y times          performs multiplication
x / y divide         performs division
x \ y inverse divide equivalent to y / x
x ^ y power          raises x to the yth power
x % y remainder      equivalent to rem(x,y)``````

as well as the negation on `Bool` types:

``````Expr. Name           Description
!x    negation       changes true to false and vice versa``````

Julia’s promotion system makes arithmetic operations on mixtures of argument types “just work” naturally and automatically. See Conversion and Promotion [prossimamente] for details of the promotion system.

Here are some simple examples using arithmetic operators: By convention, we tend to space operators more tightly if they get applied before other nearby operators. For instance, we would generally write `-x + 2` to reflect that first `x` gets negated, and then `2` is added to that result. A differenza del tutorial io tendo a lasciare spazi anche per `*` e `/`; inoltre mi piace poco `\` (divisione inversa).

Operatori bitwise
The following bitwise operators are supported on all primitive integer types:

``````Expr.   Name
~x      bitwise not
x & y   bitwise and
x | y   bitwise or
x ⊻ y   bitwise xor (exclusive or)
x >>> y logical shift right
x >> y  arithmetic shift right
x << y  logical/arithmetic shift left``````

Notare l’uso di `⊻` codice Unicode `22BB` e sì, si chiama proprio `xor`. Ma non è più semplice scrivere “`xor()`“?

Here are some examples with bitwise operators: Nota: forse è utile usare `bits` per visualizzare questi operatori Inoltre, sempre a chiarimento degli operatori sui bits si può usare `parse()`: Operatori che aggiornano
Every binary arithmetic and bitwise operator also has an updating version that assigns the result of the operation back into its left operand. The updating version of the binary operator is formed by placing a `=` immediately after the operator. For example, writing `x += 3` is equivalent to writing `x = x + 3`: The updating versions of all the binary arithmetic and bitwise operators are:

`+= -= *= /= \= ÷= %= ^= &= |= ⊻= >>>= >>= <<=`

Note: An updating operator rebinds the variable on the left-hand side. As a result, the type of the variable may change.  Posta un commento o usa questo indirizzo per il trackback.