Graal Forums

Graal Forums (https://forums.graalonline.com/forums/index.php)
-   Bug Report (https://forums.graalonline.com/forums/forumdisplay.php?f=193)
-   -   int is useless (https://forums.graalonline.com/forums/showthread.php?t=83882)

Tyhm 01-27-2009 02:49 AM

Quote:

Originally Posted by LoneAngelIbesu (Post 1460299)
It's probably more complex than you think it is. PHP is a very good language. The point I was trying to make, though, was that you should try and not use non-terminating decimals, or at least round them to terminating decimals.

Using large decimals is bound to cause problems. For instance, in GS2 "7.999969482 - 8" produces 0. But, "7.99 - 8" produces -0.01. So, I wouldn't say that int() is useless. It just faces the same problems that other languages face when it comes to floating points.

I'd love to, but it's difficult to determine if the bitflag 262143 contains 32768 (2^15th) or not without doing a little division.

LoneAngelIbesu 01-27-2009 03:20 AM

Quote:

Originally Posted by Loriel (Post 1460333)
Nice theory, except booth floor and intval get 262143/32768 right.

In PHP, maybe. We're talking about GS2 here, so we have to assume that it's going to screw up easily with large decimals, as seen when it can't correctly subtract 8 from 7.999969482. Obviously, it's rounding 7.999969482 to 8, which is also why int(7.999969482) returns 8 instead of 7.

I did a quick test on RC. int(7.999) returns 7, but int(7.9999) returns 8. int(7.9998) returns 7, as well as int(7.999899999). Considering that 7.9999 and 7.999969482 have one thing in common, it's safe to assume that when Graal sees ".9999", it'll round up to the nearest whole number.

Quote:

Originally Posted by Tyhm (Post 1460358)
I'd love to, but it's difficult to determine if the bitflag 262143 contains 32768 (2^15th) or not without doing a little division.

What are you trying to accomplish, exactly? Perhaps if you showed us the problem in context, somebody might be able to figure something out (unless you're fine with using your work-around).

Skyld 01-27-2009 04:24 AM

Quote:

Originally Posted by Tyhm (Post 1460358)
I'd love to, but it's difficult to determine if the bitflag 262143 contains 32768 (2^15th) or not without doing a little division.

if ((262143 & 32768) != 0), no?

Tyhm 01-27-2009 06:16 AM

Huh. & might work, never tried it before;
The way I've got it set up Now is, it keeps an array of rooms that connect to other rooms; the array index is the room in question, the value at that index is a bitflag of which rooms it connects to (1 means 1, 2 means 2 and not 1, 3 means 2 and 1, 4 means 3, 5 means 3 and 1, etc). When it links two rooms it simply adds the values to combine the list of linked rooms, and then updates not just those 2 rooms but every room that links to those 2 rooms.

Moral of the story is, & might work for me, but it's not gonna make me happy; what, I have to revise every int(random(0,2)) now to have a special case for if it returns 2?!

LoneAngelIbesu 01-27-2009 11:10 PM

Quote:

Originally Posted by Skyld (Post 1460379)
if ((262143 & 32768) != 0), no?

I've never noticed that kind of syntax in GS2 (single ampersand)...

Chompy 01-27-2009 11:27 PM

Quote:

Originally Posted by LoneAngelIbesu (Post 1460609)
I've never noticed that kind of syntax in GS2 (single ampersand)...

It's very practical :)

PHP Code:

function onCreated() {
  
temp.bit 2+4+16;

  if (
bit 2) echo("2");
  if (
bit 4) echo("4");
  if (
bit 8) echo("8");
  if (
bit 16) echo("16");


Echoes

Quote:

2
4
16
(move() uses this)

Loriel 01-27-2009 11:49 PM

Pseudo-bitwise operation on what amounts to floating point numbers are a bit scary. :\

WhiteDragon 01-28-2009 06:49 AM

Interesting stuff on the whole rounding issue to anyone who is interested: http://wiki.php.net/rfc/rounding


All times are GMT +2. The time now is 03:56 PM.

Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2026, vBulletin Solutions Inc.
Copyright (C) 1998-2019 Toonslab All Rights Reserved.