vault backup: 2023-09-25 13:42:45

This commit is contained in:
Louis Gallet 2023-09-25 13:42:45 +02:00
parent 58d77a9418
commit 743c2e517b
Signed by: lgallet
SSH Key Fingerprint: SHA256:qnW7pk4EoMRR0UftZLZQKSMUImbEFsiruLC7jbCHJAY

View File

@ -408,6 +408,23 @@ let power x n = match n with
| -1. -> if n mod 2 = 0 then 1. else -1.)
| _ -> (let rec p = function
| 0 -> 1.
| n -> x*.p(n-1) in p n)
| n -> (let res. = p x (n/2) in
res *. res *. (if n mod 2 = 1 then x else 1.)
in p x n)
;;
(*Correction v3*)
let power x n = match n with
| 0 -> (match x with
| 0. -> failwith "power 0^0 impossible"
| _ -> 1.)
| _ -> (match x with
| 1. -> 1.
| 0. -> 0.
| -1. -> if n mod 2 = 0 then 1. else -1.)
| _ -> (let rec p x = function
| 0 -> 1.
| n -> p (x*x) (n/2) *. (if n mod 2 = 1 then x else 1.)
in p x n)
;;
```