Graal Forums

Graal Forums (https://forums.graalonline.com/forums/index.php)
-   Future Improvements (https://forums.graalonline.com/forums/forumdisplay.php?f=10)
-   -   limit(value, min, max) (https://forums.graalonline.com/forums/showthread.php?t=87598)

fowlplay4 08-25-2009 07:26 PM

limit(value, min, max)
 
Make it a hard-coded function already regardless of how easy it is to script the function.

PHP Code:

function limit(valminmax) {
  return (
val min min : (val max max val));



WhiteDragon 08-25-2009 07:38 PM

I'd also like to see floor and ceil as run-time optimized functions.

And I've never seen this function in any other programming language, where'd you get it from?

Gambet 08-25-2009 08:17 PM

Quote:

Originally Posted by WhiteDragon (Post 1518393)
I'd also like to see floor and ceil as run-time optimized functions.


Posted about floor and ceil in the code gallery a few months back:

http://forums.graalonline.com/forums...ad.php?t=85605

fowlplay4 08-25-2009 08:18 PM

Well I'm not entirely sure if limit is the right name for it but that's how I always thought of it.

I found it first in Zodiac's initial code by Yen, it looked something like this.

PHP Code:

function limit(valminmax) {
  if (
val min) return min;
  else if (
val max) return max;
  else return 
val;


But it's come in handy for me when I am validating quantities i.e:

temp.donation = limit(temp.value, 0, player.rupees)

Or other statistic related code.

WhiteDragon 08-25-2009 08:39 PM

Quote:

Originally Posted by Gambet (Post 1518409)
Posted about floor and ceil in the code gallery a few months back:

http://forums.graalonline.com/forums...ad.php?t=85605

Yeah, I saw your thread, just I was hoping they could be built-in by Stefan, considering you can't get very good performance from anything written in GScript2 really, and floor and ceil are used in most algorithms.

Admins 08-25-2009 09:00 PM

floor==int() in graal, I'm not sure if ceil() is used often in algorithms?

fowlplay4 08-25-2009 09:13 PM

Quote:

Originally Posted by Stefan (Post 1518421)
floor==int() in graal, I'm not sure if ceil() is used often in algorithms?

Can't hurt to add them, + the limit function as posted above ;)

Crow 08-25-2009 09:49 PM

Quote:

Originally Posted by Stefan (Post 1518421)
floor==int() in graal, I'm not sure if ceil() is used often in algorithms?

It is.

WhiteDragon 08-25-2009 09:50 PM

Quote:

Originally Posted by Stefan (Post 1518421)
floor==int() in graal, I'm not sure if ceil() is used often in algorithms?

I thought int() did some weird stuff when you got into negative numbers? I recall you saying that.

I had to fake ceil() in the most recent encryption algorithm I wrote (AES/Rijndael), and I've also had to fake it for things like Boyer-Moore string searching and some things for tree structures.


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

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