Mercurial > mxe-octave
annotate src/build-msvctools/compat/csqrt.c @ 3061:f8299bb6c872
Initial support for native MSVC compilation.
* add MSVC support files: compiler wrappers and support libraries
* adapt libiconv to work with MSVC
* adapt gettext to work with MSVC
author | Michael Goffioul <michael.goffioul@gmail.com> |
---|---|
date | Mon, 17 Jun 2013 22:43:11 -0400 |
parents | |
children |
rev | line source |
---|---|
3061
f8299bb6c872
Initial support for native MSVC compilation.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
1 /* |
f8299bb6c872
Initial support for native MSVC compilation.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
2 csqrt.c |
f8299bb6c872
Initial support for native MSVC compilation.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
3 Contributed by Danny Smith |
f8299bb6c872
Initial support for native MSVC compilation.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
4 2003-10-20 |
f8299bb6c872
Initial support for native MSVC compilation.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
5 */ |
f8299bb6c872
Initial support for native MSVC compilation.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
6 |
f8299bb6c872
Initial support for native MSVC compilation.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
7 #include <math.h> |
f8299bb6c872
Initial support for native MSVC compilation.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
8 #include <complex.h> |
f8299bb6c872
Initial support for native MSVC compilation.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
9 |
f8299bb6c872
Initial support for native MSVC compilation.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
10 double complex csqrt (double complex Z) |
f8299bb6c872
Initial support for native MSVC compilation.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
11 { |
f8299bb6c872
Initial support for native MSVC compilation.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
12 double complex Res; |
f8299bb6c872
Initial support for native MSVC compilation.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
13 double t; |
f8299bb6c872
Initial support for native MSVC compilation.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
14 double x = __real__ Z; |
f8299bb6c872
Initial support for native MSVC compilation.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
15 double y = __imag__ Z; |
f8299bb6c872
Initial support for native MSVC compilation.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
16 |
f8299bb6c872
Initial support for native MSVC compilation.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
17 if (y == 0.0) |
f8299bb6c872
Initial support for native MSVC compilation.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
18 { |
f8299bb6c872
Initial support for native MSVC compilation.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
19 if (x < 0.0) |
f8299bb6c872
Initial support for native MSVC compilation.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
20 { |
f8299bb6c872
Initial support for native MSVC compilation.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
21 __real__ Res = 0.0; |
f8299bb6c872
Initial support for native MSVC compilation.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
22 __imag__ Res = sqrt (-x); |
f8299bb6c872
Initial support for native MSVC compilation.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
23 } |
f8299bb6c872
Initial support for native MSVC compilation.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
24 else |
f8299bb6c872
Initial support for native MSVC compilation.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
25 { |
f8299bb6c872
Initial support for native MSVC compilation.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
26 __real__ Res = sqrt (x); |
f8299bb6c872
Initial support for native MSVC compilation.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
27 __imag__ Res = 0.0; |
f8299bb6c872
Initial support for native MSVC compilation.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
28 } |
f8299bb6c872
Initial support for native MSVC compilation.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
29 } |
f8299bb6c872
Initial support for native MSVC compilation.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
30 |
f8299bb6c872
Initial support for native MSVC compilation.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
31 else if (x == 0.0) |
f8299bb6c872
Initial support for native MSVC compilation.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
32 { |
f8299bb6c872
Initial support for native MSVC compilation.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
33 t = sqrt(0.5 * fabs (y)); |
f8299bb6c872
Initial support for native MSVC compilation.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
34 __real__ Res = t; |
f8299bb6c872
Initial support for native MSVC compilation.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
35 __imag__ Res = y > 0 ? t : -t; |
f8299bb6c872
Initial support for native MSVC compilation.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
36 } |
f8299bb6c872
Initial support for native MSVC compilation.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
37 |
f8299bb6c872
Initial support for native MSVC compilation.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
38 else |
f8299bb6c872
Initial support for native MSVC compilation.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
39 { |
f8299bb6c872
Initial support for native MSVC compilation.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
40 t = sqrt (2.0 * (_hypot (x, y) + fabs (x))); |
f8299bb6c872
Initial support for native MSVC compilation.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
41 double u = t / 2.0; |
f8299bb6c872
Initial support for native MSVC compilation.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
42 if ( x > 0.0) |
f8299bb6c872
Initial support for native MSVC compilation.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
43 { |
f8299bb6c872
Initial support for native MSVC compilation.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
44 __real__ Res = u; |
f8299bb6c872
Initial support for native MSVC compilation.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
45 __imag__ Res = y / t; |
f8299bb6c872
Initial support for native MSVC compilation.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
46 } |
f8299bb6c872
Initial support for native MSVC compilation.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
47 else |
f8299bb6c872
Initial support for native MSVC compilation.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
48 { |
f8299bb6c872
Initial support for native MSVC compilation.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
49 __real__ Res = fabs ( y / t); |
f8299bb6c872
Initial support for native MSVC compilation.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
50 __imag__ Res = y < 0.0 ? -u : u; |
f8299bb6c872
Initial support for native MSVC compilation.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
51 } |
f8299bb6c872
Initial support for native MSVC compilation.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
52 } |
f8299bb6c872
Initial support for native MSVC compilation.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
53 |
f8299bb6c872
Initial support for native MSVC compilation.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
54 return Res; |
f8299bb6c872
Initial support for native MSVC compilation.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
55 } |
f8299bb6c872
Initial support for native MSVC compilation.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
diff
changeset
|
56 |