petdance/scratch — Issue #536: ignore print -0 test errors on win32
Author: petdance
Created: 2011-11-14 06:11:43+00:00
State: open
Labels: Pri-normal, Sev-medium, testing, todo

The win32 msvcrt has a special limitation not to print -0 as -0, instead it prints 0.
openbsd seems to have the same problem. cygwin is not affected, since it uses newlib, which is similar to the glibc in this regard.

For now I fixed the failing tests, but there should be a workaround.

```
t\pmc\complex.t:
not ok 380 - sinh of 0-2i
# Have: 0.000000-0.909297i
# Want: -0.000000-0.909297i
not ok 381 - sinh of 0+2i
# Have: 0.000000+0.909297i
# Want: -0.000000+0.909297i

t\pmc\float.t:
not ok 23 - neg 0
# Failed test 'neg 0'
# at t\pmc\float.t line 509
# '0'
# doesn't match '/^-0/
# '

t\op\arithmetics.t:
not ok 7 - turn a native number into its negative
# Failed test 'turn a native number into its negative'
# at t\op\arithmetics.t line 175.
# got: '0
# 0
# -123.456789
# 123.456789
# 0
# 0
# -123.456789
# 123.456789
# '
# expected: '-0
# 0
# -123.456789
# 123.456789
# -0
# 0
# -123.456789
# 123.456789
# '
```

The internal numeric representation seems not to be affected.
In detail, this patch does not help. It's just the printer.
```
Index: parrot-svn/src/ops/math.ops
===================================================================
--- parrot-svn.orig/src/ops/math.ops
+++ parrot-svn/src/ops/math.ops
@@ -774,7 +774,17 @@ inline op neg(inout INT) :base_core {
}

inline op neg(inout NUM) :base_core {
+#ifdef WIN32
+ /* The msvcrt is broken for neg -0.0 */
+ if ($1 == -0.0) {
+ $1 = -0.0;
+ }
+ else {
+ $1 = - $1;
+ }
+#else
$1 = - $1;
+#endif
}

inline op neg(invar PMC) :base_core {
@@ -786,7 +796,17 @@ inline op neg(out INT, in INT) :base_cor
}

inline op neg(out NUM, in NUM) :base_core {
+#ifdef WIN32
+ /* The msvcrt is broken for neg -0.0 */
+ if ($2 == -0.0) {
+ $1 = -0.0;
+ }
+ else {
+ $1 = - $1;
+ }
+#else
$1 = - $2;
+#endif
}

inline op neg(out PMC, invar PMC) :base_core {
```

Originally http://trac.parrot.org/parrot/ticket/313 by rurban (@rurban)