Hi -

On 5/21/15, 7:42 AM, "Damian McGuckin" <[email protected]> wrote:
>
>Why would a 32 bit floating point number multiplied by a 32 bit integer
>yield a 64 bit quantity? Is Chapel trying to avoid overflow?

Yes. This behavior matches the language specification.

In section 9.1.1, it says that int(32) won't coerce to real(32)
since a real(32) can't represent an int(32) without loss of precision.
Note though that int(64) can coerce to real(64) as "an important
convenience."

Then, in section 10.13.5, the spec says that * is only defined for the
same type.

Function resolution could not find *(real(32), int(32)), but it
did find *(real(64), real(64)) since real(32) can coerce to real(64)
and int(32) can coerce to real(64).

Modifying your program like this provides the behavior you expected:


  var x : real(32) = 0.5:real(32);
  var i : int(32) = 12345;
  var m = x * (i:real(32));

  if m.type == real(64) then
  {
    writeln("64 bits was seen");
  }
  else
  {
    writeln("I expect 32 bits");
  }



I'd be interested to know your thoughts on this property - do
you think that int(32) should coerce to real(32)?

Cheers,

-michael


------------------------------------------------------------------------------
One dashboard for servers and applications across Physical-Virtual-Cloud 
Widest out-of-the-box monitoring support with 50+ applications
Performance metrics, stats and reports that give you Actionable Insights
Deep dive visibility with transaction tracing using APM Insight.
http://ad.doubleclick.net/ddm/clk/290420510;117567292;y
_______________________________________________
Chapel-users mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/chapel-users

Reply via email to