Subject: Re: Conversion to double. From: Aaron Albertson Date: Wed, 1 Jun 2011 15:50:35 -0500 List-archive: List-help: List-id: C programming iSeries / AS400 List-post: List-subscribe: , List-unsubscribe: ,

Hi Chris,

In the expression "(double)(2482884 * 1024)" the cast to double is done
against the result of the expression "(2482884 * 1024)". The "(2482884 *
1024)" expression is evaluated first, and when it is parsed the operands
are two integer values. They are the same type so no implicit conversion
is necessary and the result is a (wrapped) integer value. This value is
then converted to double by the cast.

When you move the conversion inside the parentheses, as you do in your
second two examples, the multiplication expression will have two operands
of type double and the result will be of type double as well, resulting in
no wrap.

Aaron Albertson

c400-l-bounces+albertaa=us.ibm.com@xxxxxxxxxxxx wrote on 06/01/2011
11:17:23 AM:

From: "Chris Hird" <chrish@xxxxxxxxxxxxxxxxx>
To: <c400-l@xxxxxxxxxxxx>
Date: 06/01/2011 03:11 PM
Subject: [C400-L] Conversion to double.
Sent by: c400-l-bounces+albertaa=us.ibm.com@xxxxxxxxxxxx

Hi

Not sure why I struggled with this one but.

Printf(“%f\n”,(double)(2482884 * 1024)); shows -1752494080.000000

Printf(“%f\n”,(2482884.0 * 1024.0)); shows 2542473216.000000

Printf(“%f\n”,((double)2482884 * (double)1024)); shows 2542473216.000000

It seems like the conversion to double does not work in the first
instance.
Am I doing something wrong? Shouldn’t the cast of the result make the
number correct?

Chris…

___________________________­­­­­­­­­­­­­­­­­­­­­­­__________________________
_

Please consider the environment before printing this email.

This message, including any attached documents, is intended for the
addressees only. It may contain information that is confidential,
privileged
and/or exempt from disclosure. No rights to privilege or confidentiality
have been waived. Any unauthorized use or disclosure is prohibited. If
you
and delete or destroy all copies of this message.

______________________________________________________

Avant d'imprimer ce courriel, pensez à l'environnement.

Ce message, incluant tous les documents joints, est à l'intention des
destinataires visés seulement. Il peut contenir des renseignements
confidentiels, protégés et/ou ne pouvant pas être divulgués. Aucune
renonciation n'est faite quant à sa nature confidentielle et privilégiée.
Par conséquent, toute diffusion ou utilisation non autorisée est
strictement
interdite. Si vous avez reçu ce message par erreur, veuillez en aviser
immédiatement l'expéditeur par retour de courriel et en détruire toutes
les
copies existantes.

--
This is the C programming iSeries / AS400 (C400-L) mailing list
To post a message email: C400-L@xxxxxxxxxxxx
To subscribe, unsubscribe, or change list options,
visit: http://lists.midrange.com/mailman/listinfo/c400-l
or email: C400-L-request@xxxxxxxxxxxx
Before posting, please take a moment to review the archives
at http://archive.midrange.com/c400-l.

As an Amazon Associate we earn from qualifying purchases.