Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.os.linux.development.apps > #447

Re: cast double to short problem

From Grant Edwards <invalid@invalid.invalid>
Newsgroups comp.os.linux.development.apps
Subject Re: cast double to short problem
Date 2012-03-07 00:30 +0000
Organization PANIX Public Access Internet and UNIX, NYC
Message-ID <jj6a7s$l7k$1@reader1.panix.com> (permalink)
References <jj64g2$fb8$1@dont-email.me> <jj6650$fa0$1@reader1.panix.com> <jj6714$tbh$1@dont-email.me>

Show all headers | View raw


On 2012-03-06, Bill M <wpmccormick@just_about_everywhere.com> wrote:

>> What exactly are you trying to accomplish with the above code?
>
> I need to interface to another system that does not accept floating 
> point values. It's interface specifies that certain values are X 10. 
> other are X 100.

> Sounds like maybe what I need is a intermediate round operation?

What you were doing was truncating (2.999999999999999 -> 2), and I
suspect you want is indeed rounding to the nearest integer FP value
followed by the conversion to integer:

 2.999999999999999 -> 3.0000000000000 -> 3

 
$ man round

#include <math.h>

i = (short) round(MyDoubleValue * 100.0);



  

Back to comp.os.linux.development.apps | Previous | NextPrevious in thread | Next in thread | Find similar


Thread

cast double to short problem Bill M <wpmccormick@just_about_everywhere.com> - 2012-03-06 16:52 -0600
  Re: cast double to short problem Grant Edwards <invalid@invalid.invalid> - 2012-03-06 23:21 +0000
    Re: cast double to short problem Bill M <wpmccormick@just_about_everywhere.com> - 2012-03-06 17:36 -0600
      Re: cast double to short problem Grant Edwards <invalid@invalid.invalid> - 2012-03-07 00:30 +0000
        Re: cast double to short problem Noob <root@127.0.0.1> - 2012-03-07 11:17 +0100
          Re: cast double to short problem Grant Edwards <invalid@invalid.invalid> - 2012-03-07 15:23 +0000
    Re: cast double to short problem "Ersek, Laszlo" <lacos@caesar.elte.hu> - 2012-03-07 19:33 +0100
      Re: cast double to short problem Grant Edwards <invalid@invalid.invalid> - 2012-03-07 20:13 +0000
        Re: cast double to short problem Bill M <wpmccormick@just_about_everywhere.com> - 2012-03-08 11:45 -0600

csiph-web