Raised This Month: $12 Target: $400
 3% 

[EXTENSION] Double extension


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
Xutax_Kamay
Member
Join Date: Feb 2016
Old 02-16-2020 , 08:35   [EXTENSION] Double extension
Reply With Quote #1

Hello!

I'm sharing here a small extension to use doubles in SP.
I'm sorry, there is no windows binaries yet, I'll upload them when I get my VM setup.

Please make an issue here if you encounter any issues: https://github.com/XutaxKamay/double_ext
Thanks.

Credits:
kidfearless for spamming me to do it

For releases, please check github link.

Last edited by Xutax_Kamay; 02-16-2020 at 12:59.
Xutax_Kamay is offline
kidfearless
Junior Member
Join Date: Jun 2017
Old 02-16-2020 , 08:38   Re: [EXTENSION] Double extension
Reply With Quote #2

Eyyy he's finally done it. Thanks kamay, this will help a lot.

Edit: As a note for anyone interested in this extension. The static methods will return a new handle, and the Reference methods will modify the current handle.

Last edited by kidfearless; 02-16-2020 at 09:13.
kidfearless is offline
DragShot
Junior Member
Join Date: Feb 2020
Location: Lima, Peru
Old 02-16-2020 , 12:10   Re: [EXTENSION] Double extension
Reply With Quote #3

Oh that's very nice. I've always been wary of floats since you never know when you're going to run out of accuracy (that has actually happened to me a couple of times), so it's pretty cool to see people can actually port native types like this to sourcemod plugins. I'm loving how lightweight yet flexible this environment can be.

Last edited by DragShot; 02-16-2020 at 12:15.
DragShot is offline
Xutax_Kamay
Member
Join Date: Feb 2016
Old 02-16-2020 , 12:56   Re: [EXTENSION] Double extension
Reply With Quote #4

Quote:
Originally Posted by DragShot View Post
Oh that's very nice. I've always been wary of floats since you never know when you're going to run out of accuracy (that has actually happened to me a couple of times), so it's pretty cool to see people can actually port native types like this to sourcemod plugins. I'm loving how lightweight yet flexible this environment can be.
Thank you, I appreciate.
Well personally, I do like sourcepawn in fact for some stuffs because it makes things much more easier, but I think I'll always end up to make my plugins from c++ straight because of some limitations that sourcemod offers. I would have liked it more if it had offered natives for just c++ plugins for example, so you could do more things in back end. (I mean theorically you could just make an extension and use the natives but yeah)
But yeah, I think too sourcemod has probably the most advanced functionality in terms of game modding compared to others games especially on a multiplayer game I guess.

Last edited by Xutax_Kamay; 02-16-2020 at 13:00.
Xutax_Kamay is offline
TheDS1337
Veteran Member
Join Date: Jun 2012
Old 02-16-2020 , 13:22   Re: [EXTENSION] Double extension
Reply With Quote #5

What would be the usage of this? I don't think anybody doing sm is going to do some numerical analysis to care enough about such precisions.
TheDS1337 is offline
nosoop
Veteran Member
Join Date: Aug 2014
Old 02-17-2020 , 05:03   Re: [EXTENSION] Double extension
Reply With Quote #6

This doesn't seem like an extension that needs game-specific builds; I'll send in a PR for that shortly.

May want to rework your tests as Double.FromFloat(1234.34567) loses precision and is rendered as 1234.345703125; would recommend the testing includes for that.

Quote:
Originally Posted by TheDS1337 View Post
What would be the usage of this? I don't think anybody doing sm is going to do some numerical analysis to care enough about such precisions.
I've actually needed to work with doubles pretty much once in SourceMod (TF2's sentry think ticks uses that type in memory, for whatever reason, and I needed to override it). In that particular case I ended up going with extremely manual bit-twiddling for float / double conversion, but this would've been pretty nice to work with provided it could give me the value as a cell_t[2] (enum struct, perhaps?).

While I don't have a personal use for it, I could imagine it being handy for physics calculations or long-running operations. ¯\_(ツ)_/¯
__________________
I do TF2, TF2 servers, and TF2 plugins.
I don't do DMs over Discord -- PM me on the forums regarding inquiries.
AlliedModders Releases / Github / TF2 Server / Donate (BTC / BCH / coffee)

Last edited by nosoop; 02-17-2020 at 05:23.
nosoop is offline
Xutax_Kamay
Member
Join Date: Feb 2016
Old 02-17-2020 , 09:49   Re: [EXTENSION] Double extension
Reply With Quote #7

About its usage, well some of my friends needed it for a bhop/surf timer and some other things related to an anti-cheat, I'm just sharing it there so nobody needs to write repetitive functions and make it into an extension in case people need it.
It could be bring up modulo since it doesn't exist in sourcepawn I think?

Quote:
Originally Posted by nosoop View Post
This doesn't seem like an extension that needs game-specific builds; I'll send in a PR for that shortly.

May want to rework your tests as Double.FromFloat(1234.34567) loses precision and is rendered as 1234.345703125; would recommend the testing includes for that.



I've actually needed to work with doubles pretty much once in SourceMod (TF2's sentry think ticks uses that type in memory, for whatever reason, and I needed to override it). In that particular case I ended up going with extremely manual bit-twiddling for float / double conversion, but this would've been pretty nice to work with provided it could give me the value as a cell_t[2] (enum struct, perhaps?).

While I don't have a personal use for it, I could imagine it being handy for physics calculations or long-running operations. ¯\_(ツ)_/¯
Haha yeah you're right it doesn't need game specific builds, I was just too lazy to change it this way, but thanks for willing to put efforts into it.

As you said 1234.34570312 looses precision for some reasons I don't really know yet I think during casting to double, compiler optimization makes it loose precision, I need to investigate, but yeah bit manipulation should be way enough if sourcemod doesn't break the encoding of the float behind when it passes through cells. Float should be encoded with 0x449A4B10 (0x4093496200000000 for double) and not decoding after 1234.34567...
Though I heard FromString was working correctly.

And yeah I was thinking before making the extension about using two cells_t to encode the double, but I just said to myself that FromString is enough.

Anyway feel free to do any modifications you'd like I'll accept your PR once it's done (I didn't know about the testing include, it's nice)

Last edited by Xutax_Kamay; 02-17-2020 at 09:52.
Xutax_Kamay is offline
Reply


Thread Tools
Display Modes

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 -4. The time now is 10:10.


Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.
Theme made by Freecode