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

**URL:** <https://chapel.discourse.group/t/formatted-output-with-7-3dr-fails-with-0-0/9849>\
**Category:** Users\
**Created:** [January 23, 2022, 11:37am UTC](https://chapel.discourse.group/t/formatted-output-with-7-3dr-fails-with-0-0/9849 "2022-01-23T11:37:15Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![damianmoz](https://yyz2.discourse-cdn.com/free1/user_avatar/chapel.discourse.group/damianmoz/32/319_2.png) [@damianmoz](https://chapel.discourse.group/u/damianmoz)\
**Post date:** [January 23, 2022, 11:37am UTC](https://chapel.discourse.group/t/formatted-output-with-7-3dr-fails-with-0-0/9849/1 "2022-01-23T11:37:15Z")

</div>

It prints "+0.000"

Not urgent.

---

<div class="post-metadata">

**Author:** ![mppf](https://avatars.discourse-cdn.com/v4/letter/m/94ad74/32.png) [@mppf](https://chapel.discourse.group/u/mppf)\
**Post date:** [January 24, 2022, 3:18pm UTC](https://chapel.discourse.group/t/formatted-output-with-7-3dr-fails-with-0-0/9849/2 "2022-01-24T15:18:50Z")

</div>

Hi Damian -

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

```Chapel
var x = -0.0;

writeln(signbit(x));

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

```

```Chapel
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?

---

<div class="post-metadata">

**Author:** ![damianmoz](https://yyz2.discourse-cdn.com/free1/user_avatar/chapel.discourse.group/damianmoz/32/319_2.png) [@damianmoz](https://chapel.discourse.group/u/damianmoz)\
**Post date:** [February 23, 2022, 10:25am UTC](https://chapel.discourse.group/t/formatted-output-with-7-3dr-fails-with-0-0/9849/3 "2022-02-23T10:25:23Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![damianmoz](https://yyz2.discourse-cdn.com/free1/user_avatar/chapel.discourse.group/damianmoz/32/319_2.png) [@damianmoz](https://chapel.discourse.group/u/damianmoz)\
**Post date:** [February 23, 2022, 10:42am UTC](https://chapel.discourse.group/t/formatted-output-with-7-3dr-fails-with-0-0/9849/4 "2022-02-23T10:42:45Z")

</div>

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.

```chapel
// 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!

---

<div class="post-metadata">

**Author:** ![mppf](https://avatars.discourse-cdn.com/v4/letter/m/94ad74/32.png) [@mppf](https://chapel.discourse.group/u/mppf)\
**Post date:** [February 23, 2022, 3:54pm UTC](https://chapel.discourse.group/t/formatted-output-with-7-3dr-fails-with-0-0/9849/5 "2022-02-23T15:54:47Z")

</div>

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

```Chapel
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?

---

<div class="post-metadata">

**Author:** ![damianmoz](https://yyz2.discourse-cdn.com/free1/user_avatar/chapel.discourse.group/damianmoz/32/319_2.png) [@damianmoz](https://chapel.discourse.group/u/damianmoz)\
**Post date:** [February 23, 2022, 5:25pm UTC](https://chapel.discourse.group/t/formatted-output-with-7-3dr-fails-with-0-0/9849/6 "2022-02-23T17:25:03Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![mppf](https://avatars.discourse-cdn.com/v4/letter/m/94ad74/32.png) [@mppf](https://chapel.discourse.group/u/mppf)\
**Post date:** [February 23, 2022, 6:28pm UTC](https://chapel.discourse.group/t/formatted-output-with-7-3dr-fails-with-0-0/9849/7 "2022-02-23T18:28:29Z")

</div>

FYI on older CentOS I've had success installing a newer GCC with a devtoolset package. See [Developer Toolset 8 — Software Collections](https://www.softwarecollections.org/en/scls/rhscl/devtoolset-8/)

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.

---

<div class="post-metadata">

**Author:** ![damianmoz](https://yyz2.discourse-cdn.com/free1/user_avatar/chapel.discourse.group/damianmoz/32/319_2.png) [@damianmoz](https://chapel.discourse.group/u/damianmoz)\
**Post date:** [February 24, 2022, 5:55am UTC](https://chapel.discourse.group/t/formatted-output-with-7-3dr-fails-with-0-0/9849/8 "2022-02-24T05:55:36Z")

</div>

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.
