Formatted output with "%7.3dr" fails with "-0.0"

It prints "+0.000"

Not urgent.

Hi Damian -

This thread seems more like a bug report. Anyway this worked for me:

var x = -0.0;

writeln(signbit(x));

writef("%7.3dr\n", x);
true
 -0.000

I see this on two different systems with or without --fast. So, could you make a bug report issue that also says more about your configuration?

1 Like

Sorry, only just noticed you had replied Michael. I will get onto it. Again, apologies.

Apologies, the problem was deeper than the formatting.

You were far wiser than me by checking the signbit beforehand.

The real culprit is the casting of a tuple to a complex.

Please try this.

// this is a real man's creation of a complex from its
// real and imaginary components, the latter as a real

proc cmplx(x : real(?w), y : real(w))
{
    var t : complex(w << 1);

    t.re = x;
    t.im = y;
    return t;
}


var x : complex(64) = (1.0:real(32), -0.0:real(32)):complex(64);
var y = cmplx(1.0:real(32), -0.0:real(32));

writeln("use standard Chapel casting of a tuple of 2 real to create complex");
writeln(signbit(x.re), " and ", signbit(x.im));
writef("%+7.3dr %+7.3dr i\n", x.re, x.im);

x = y;

writeln("use the 'cmplx' method to create complex from 2 individual reals");
writeln(signbit(x.re), " and ", signbit(x.im));
writef("%+7.3dr %+7.3dr i\n", x.re, x.im);

Have fun!

I am not seeing the problem. Your program has this output for me

use standard Chapel casting of a tuple of 2 real to create complex
false and true
 +1.000  -0.000 i
use the 'cmplx' method to create complex from 2 individual reals
false and true
 +1.000  -0.000 i

Is that not the output you expected? It seems to be what I would expect. Am I missing something?

1 Like

I see a plus sign on the 2nd line

using standard Chapel casting of a tuple of 2 real to create complex
false and false
+1.000 +0.000 i
using the 'cmplx' method to create complex from 2 individual reals
false and true
+1.000 -0.000 i

I am stuck with 1.22.0 because I cannot compile chapel 1.24.0 or above on my CentOS system.. And when I went digging into the compiler, I did not see changes. But I did not look where that casting was handled.

Sorry for the distraction.

We upgrade to CentOS 7.9 across the board so hopefully it has the tools, or I can add the tools, to handle the latest compiler.

FYI on older CentOS I've had success installing a newer GCC with a devtoolset package. See Developer Toolset 8 — Software Collections

I tried 1.22.1 on a recent Mac OS X system and still the program works as I showed before. So there may yet be something about your environment that causes the problem. I think the next step is to try it in your environment on the latest Chapel release.

1 Like

I managed to get some time on another machine with 1.22.0 under CentOS 7.

Probably does not exist in that environment. Sorry for the red-herring.