Graal Forums  

Go Back   Graal Forums > Development Forums > NPC Scripting > Code Gallery
FAQ Members List Calendar Today's Posts

Reply
 
Thread Tools Search this Thread Display Modes
  #1  
Old 05-17-2009, 02:57 AM
Gambet Gambet is offline
Registered User
Join Date: Oct 2003
Posts: 2,712
Gambet is on a distinguished road
floor() and ceil() functions

After testing the floor() function I came to realize that it does not work. To double check, I asked napo to test it out, and he also concluded that it does not work. While noticing that the floor() function does not work, I realized that there is also not a ceil() function (or at least I can't find one anywhere), so I made both in hopes that it's updated into the engine.


Simple enough, really:

PHP Code:
public function ceil(num) {
 if (
int(num) != num)
  return 
int(num) + 1;
 else return 
num;
}

public function 
floor(num) {
 return 
int(num);

Reply With Quote
  #2  
Old 05-27-2009, 08:00 PM
Pelikano Pelikano is offline
Registered User
Pelikano's Avatar
Join Date: Oct 2008
Posts: 1,133
Pelikano has a little shameless behaviour in the past
I don't get it :S

What does floor() do?
It basically just does int() :S
Reply With Quote
  #3  
Old 05-27-2009, 08:12 PM
Gambet Gambet is offline
Registered User
Join Date: Oct 2003
Posts: 2,712
Gambet is on a distinguished road
The floor function finds the greatest integer less than or equal to a specified number. The ceiling function finds the smallest integer greater than or equal to a specifed number. These functions can be found in just about all programming languages.

In Graal, int(num) truncates the number, which in essence is what the floor function is supposed to do, so it's the same thing basically when using it on Graal.
Reply With Quote
  #4  
Old 05-27-2009, 08:53 PM
Admins Admins is offline
Graal Administration
Join Date: Jan 2000
Location: Admins
Posts: 11,693
Admins has much to be proud ofAdmins has much to be proud ofAdmins has much to be proud ofAdmins has much to be proud ofAdmins has much to be proud ofAdmins has much to be proud of
Yes int() acts different on normal C/C++ for negative numbers, int(-1.1) in graal is -2, while it's -1 in C/C++ which can mess up a lot of calculations.
Reply With Quote
Reply


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +2. The time now is 05:49 AM.


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