YetAnotherForum
Welcome Guest Search | Active Topics | Log In | Register

No floor/ceil/round functions?
Kelvin
#1 Posted : Sunday, January 20, 2019 8:18:03 PM(UTC)
Rank: Advanced Member

Groups: Registered, Moderator
Joined: 3/26/2015(UTC)
Posts: 55
Man
Location: Georgia

Thanks: 3 times
Was thanked: 0 time(s) in 0 post(s)
I swear I remember seeing these mentioned in one of the documentations, but when I tried to use them in my code, the runtime said those functions didn't exist. I mean, it wasn't hard to make bindings for them myself, but I feel like math functions as commonly-used as those should be build in standard.
Sam
#2 Posted : Monday, January 28, 2019 1:40:53 PM(UTC)
Rank: Newbie

Groups: Registered
Joined: 11/18/2018(UTC)
Posts: 1

Thanks: 0 times
Was thanked: 0 time(s) in 0 post(s)
They are included in the standard math library. Make sure you're using the correct syntax.

http://www.squirrel-lang.../sqstdlib3.html#d0e1540

Code:
print( floor(2.3) )
Kelvin
#3 Posted : Wednesday, February 6, 2019 5:43:40 AM(UTC)
Rank: Advanced Member

Groups: Registered, Moderator
Joined: 3/26/2015(UTC)
Posts: 55
Man
Location: Georgia

Thanks: 3 times
Was thanked: 0 time(s) in 0 post(s)
Tried that exact code without floor embedded by myself.

Code:
AN ERROR HAS OCCURED [the index 'floor' does not exist]

CALLSTACK
*FUNCTION [main()] test.nut line [1]

LOCALS
[vargv] ARRAY
[this] TABLE
absence
#4 Posted : Friday, February 22, 2019 8:56:37 AM(UTC)
Rank: Advanced Member

Groups: Registered
Joined: 8/23/2014(UTC)
Posts: 133
Man
Location: Northern Germany & Lincolnshire, U.K.

Thanks: 2 times
Was thanked: 10 time(s) in 10 post(s)
floor is implemented in the math library.
Possibly your C++ application does not have it?

(or your using floor within a scope where the environment is two-stage -> the root table is not accessible. In that case, for example print() will also fail. If so, try using ::floor )
Kelvin
#5 Posted : Saturday, February 23, 2019 10:20:33 PM(UTC)
Rank: Advanced Member

Groups: Registered, Moderator
Joined: 3/26/2015(UTC)
Posts: 55
Man
Location: Georgia

Thanks: 3 times
Was thanked: 0 time(s) in 0 post(s)
Ah, that might be the case in my main project. I'm calling floor() from within a function within a class. As for my testbed, yeah, I was missing the math library. My bad. XD However, embedding it myself made it accessible without needing to do ::floor(), so I wonder why it needs that when using the standard library.
absence
#6 Posted : Monday, April 29, 2019 7:25:25 AM(UTC)
Rank: Advanced Member

Groups: Registered
Joined: 8/23/2014(UTC)
Posts: 133
Man
Location: Northern Germany & Lincolnshire, U.K.

Thanks: 2 times
Was thanked: 10 time(s) in 10 post(s)
That's because all standard lib bindings are in the root table, and it depends on the environment (delegate/this-object) wether Squirrel finds it. The double colons let it refer to the root table in all cases.

imagine this

class foo()
{
function floor() { return 0.7; };
function bar(x) { return ::floor(x); };
}

if the double colons were missing in bar(), it would refer to foo:floor instead.
Another case could be the default delegate of the current "this" object got changed or the this object is nested within other tables, because squirrel does not iterate all the way but just goes down one level when searching for a function name.


Users browsing this topic
Guest
Forum Jump  
You cannot post new topics in this forum.
You cannot reply to topics in this forum.
You cannot delete your posts in this forum.
You cannot edit your posts in this forum.
You cannot create polls in this forum.
You cannot vote in polls in this forum.

Clean Slate theme by Jaben Cargman (Tiny Gecko)
Powered by YAF 1.9.4 | YAF © 2003-2010, Yet Another Forum.NET
This page was generated in 0.259 seconds.