Raised This Month: $32 Target: $400
 8% 

Solved view_as<float> using


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
Dragokas
Veteran Member
Join Date: Nov 2017
Location: Ukraine on fire
Old 05-26-2018 , 15:42   view_as<float> using
Reply With Quote #1

Hi,

Code:
	int damage = 3000;
	PrintToServer("float = %f", view_as<float>(damage));
Quote:
float = 0.000000
Why?
__________________
Expert of CMD/VBS/VB6. Malware analyst. L4D fun (Bloody Witch & FreeZone)
[My plugins] [My tools] [GitHub] [Articles] [HiJackThis+] [Donate]

Last edited by Dragokas; 05-27-2018 at 21:18.
Dragokas is offline
Visual77
Veteran Member
Join Date: Jan 2009
Old 05-26-2018 , 15:47   Re: view_as<float> using
Reply With Quote #2

Code:
PrintToServer("float = %f", float(damage));
We don't use view_as when we want to convert from one type to another.
view_as<float> would require whatever is inside ( ) to also be float.

Last edited by Visual77; 05-26-2018 at 15:50.
Visual77 is offline
Dragokas
Veteran Member
Join Date: Nov 2017
Location: Ukraine on fire
Old 05-26-2018 , 15:48   Re: view_as<float> using
Reply With Quote #3

ok thanks.

But, why?
__________________
Expert of CMD/VBS/VB6. Malware analyst. L4D fun (Bloody Witch & FreeZone)
[My plugins] [My tools] [GitHub] [Articles] [HiJackThis+] [Donate]
Dragokas is offline
Fyren
FyrenFyrenFyrenFyrenFyren FyrenFyrenFyrenFyrenFyren FyrenFyrenFyrenFyrenFyren FyrenFyrenFyrenFyrenFyren
Join Date: Feb 2106
Old 05-26-2018 , 15:52   Re: view_as<float> using
Reply With Quote #4

Because those bits are going to make a float that's less than 2^-126.
Fyren is offline
Dragokas
Veteran Member
Join Date: Nov 2017
Location: Ukraine on fire
Old 05-26-2018 , 16:43   Re: view_as<float> using
Reply With Quote #5

Wait, what rules is it cast with? memcpy?
__________________
Expert of CMD/VBS/VB6. Malware analyst. L4D fun (Bloody Witch & FreeZone)
[My plugins] [My tools] [GitHub] [Articles] [HiJackThis+] [Donate]
Dragokas is offline
ddhoward
Veteran Member
Join Date: May 2012
Location: California
Old 05-26-2018 , 17:46   Re: view_as<float> using
Reply With Quote #6

view_as is not a cast, it's just a retag.
__________________
ddhoward is offline
klippy
AlliedModders Donor
Join Date: May 2013
Location: Serbia
Old 05-26-2018 , 18:42   Re: view_as<float> using
Reply With Quote #7

memcpy, reinterpret_cast<T>, whatever you are familiar with. view_as<T> is just a re-interpretation of bytes.
__________________
klippy is offline
headline
SourceMod Moderator
Join Date: Mar 2015
Old 05-27-2018 , 19:33   Re: view_as<float> using
Reply With Quote #8

You're looking for
PHP Code:
int damage 3000;
PrintToServer("float = %f"float(damage)); 
headline 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 19:04.


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