Results 1 to 6 of 6

Thread: Converting/casting cpp datatypes

  1. #1

    Converting/casting cpp datatypes

    Hi,

    I'm converting some cpp code to work in my pascal project.
    (BjA¬?rn BergstrA¬?m's recursive shadowcasting)

    The following line that casts from integer to double to integer, where xCenter is an integer:
    int xStart=(int)((double)xCenter + 0.5 - (startSlope * distance));

    xStart := Integer( Double(xCenter) + 0.5 - (startSlope * distance) ) yields an invalid typecast error.

    So I though about doing something like this:
    xStart := Round( xCenter + 0.5 - (StartSlope * distance) );

    Would this give the correct result ?

    Thanks,
    Balaras
    I've been trying for some time to develop a lifestyle that doesn't require my presence. - G.B. Trudeau

  2. #2

    Converting/casting cpp datatypes

    That should do the trick..but...if the origional code just returned the whole number without rounding (which I suspect it would) I would say use Trunc instead.

    Dean
    <A HREF="http://www.myhpf.co.uk/banner.asp?friend=139328">
    <br /><IMG SRC="http://www.myhpf.co.uk/banners/60x468.gif" BORDER="0">
    <br /></A>

  3. #3

    Converting/casting cpp datatypes

    Thanks Dean,

    To truncate a real would be the equivallent of floor() right ?

    Balaras
    I've been trying for some time to develop a lifestyle that doesn't require my presence. - G.B. Trudeau

  4. #4

    Converting/casting cpp datatypes

    I think so.
    <A HREF="http://www.myhpf.co.uk/banner.asp?friend=139328">
    <br /><IMG SRC="http://www.myhpf.co.uk/banners/60x468.gif" BORDER="0">
    <br /></A>

  5. #5

    Converting/casting cpp datatypes

    IIRC it should be:
    xStart := TRUNC( xCenter + 0.5 - (StartSlope * distance) );
    There are only 10 types of people in this world; those who understand binary and those who don't.

  6. #6

    Converting/casting cpp datatypes

    Thanks both of you.
    I've been trying for some time to develop a lifestyle that doesn't require my presence. - G.B. Trudeau

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •