My working unpac repository

Use Float.hypot to implement Complex.norm (#10786)

authored by

Christophe Troestler and committed by
GitHub
a0ef6285 dc79f481

+6 -9
+3
Changes
··· 262 262 OCaml. 263 263 (Damien Doligez, review by Stephen Dolan) 264 264 265 + - #10786: The implementation of Complex.norm now uses Float.hypot. 266 + (Christophe Troestler, review by David Allsopp and Xavier Leroy) 267 + 265 268 ### Other libraries: 266 269 267 270 - #10192: Add support for Unix domain sockets on Windows and use them
+2
stdlib/.depend
··· 189 189 stdlib__Char.cmi 190 190 stdlib__Char.cmi : char.mli 191 191 stdlib__Complex.cmo : complex.ml \ 192 + stdlib__Float.cmi \ 192 193 stdlib__Complex.cmi 193 194 stdlib__Complex.cmx : complex.ml \ 195 + stdlib__Float.cmx \ 194 196 stdlib__Complex.cmi 195 197 stdlib__Complex.cmi : complex.mli 196 198 stdlib__Condition.cmo : condition.ml \
+1 -9
stdlib/complex.ml
··· 48 48 49 49 let norm2 x = x.re *. x.re +. x.im *. x.im 50 50 51 - let norm x = 52 - (* Watch out for overflow in computing re^2 + im^2 *) 53 - let r = abs_float x.re and i = abs_float x.im in 54 - if r = 0.0 then i 55 - else if i = 0.0 then r 56 - else if r >= i then 57 - let q = i /. r in r *. sqrt(1.0 +. q *. q) 58 - else 59 - let q = r /. i in i *. sqrt(1.0 +. q *. q) 51 + let norm x = Float.hypot x.re x.im 60 52 61 53 let arg x = atan2 x.im x.re 62 54