logo
Main

Forums

Downloads

Unreal-Netiquette

Donate for Oldunreal:
Donate

borderline

Links to our wiki:
Wiki

Walkthrough

Links

Tutorials

Unreal Reference

Usermaps

borderline

Contact us:
Submit News
Page Index Toggle Pages: 1 Send TopicPrint
Normal Topic Add Pow() function to Object (Read 367 times)
han
Global Moderator
Unreal Rendering Guru
Developer Team
*****
Offline


Oldunreal member

Posts: 478
Location: Germany
Joined: Dec 10th, 2014
Gender: Male
Add Pow() function to Object
Jan 14th, 2017 at 4:37pm
Print Post  
I today noticed that Pow() is missing in UnrealScript, and after checking 227 I was suprised that it is missing there. This should really be added.

Arguable, there should be added a lot of the missing standard math functions (asin,acos,atan2,cosh,sinh,etc.,etc.).
  

HX on Mod DB. Revision on Steam.
Back to top
 
IP Logged
 
Masterkent
Developer Team
Offline



Posts: 793
Location: Russia
Joined: Apr 5th, 2013
Gender: Male
Re: Add Pow() function to Object
Reply #1 - Jan 16th, 2017 at 2:49pm
Print Post  
han wrote on Jan 14th, 2017 at 4:37pm:
I today noticed that Pow() is missing in UnrealScript, and after checking 227 I was suprised that it is missing there.

I presume, it's rarely needed in game. For those rare cases when fractional power is needed, Exp(Loge(X) * Y) could suffice.

Quote:
Arguable, there should be added a lot of the missing standard math functions (asin,acos,atan2,cosh,sinh,etc.,etc.).

ACos is present. ASin(X) can be calculated as (Pi/2 - ACos(X)). ATan2 could be useful. For hyperbolic functions I can't imagine any non-contrived use cases within a game.
  
Back to top
 
IP Logged
 
han
Global Moderator
Unreal Rendering Guru
Developer Team
*****
Offline


Oldunreal member

Posts: 478
Location: Germany
Joined: Dec 10th, 2014
Gender: Male
Re: Add Pow() function to Object
Reply #2 - Jan 17th, 2017 at 1:11am
Print Post  
In the end I went with Exp(Y*Loge(X)), as my function was piecewise defined, so that this identity just works for for X>0 wasn't an issue.

I didn't notice ACos. However, especially the Pow approach might be way less numerically stable and slower and same as the ASin workaround, less readable.

However the basic reason for my suggestion is more an easy of use and some sort of completetion of the standard mathematical functions typically featured inside a language. Adding them has no whatsover sideeffects on any other portions of the code, while at the same time these certainly do pose a standard feature set of a language.

It's to early to come up with a better contrived use case as like someone wants to cr render a hyperbolic komet in his sky box, but for me the hyperbolic functions are nothing special, but just one in the same line as the trigonometric functions, exponential, etc. basically some every days maths functions you see over and over again.
  

HX on Mod DB. Revision on Steam.
Back to top
 
IP Logged
 
Smirftsch
Forum Administrator
*****
Offline



Posts: 7375
Location: at home
Joined: Apr 30th, 1998
Gender: Male
Re: Add Pow() function to Object
Reply #3 - Jan 17th, 2017 at 6:55am
Print Post  
han wrote on Jan 14th, 2017 at 4:37pm:
I today noticed that Pow() is missing in UnrealScript, and after checking 227 I was suprised that it is missing there. This should really be added.

Arguable, there should be added a lot of the missing standard math functions (asin,acos,atan2,cosh,sinh,etc.,etc.).


what's again the c++ corresponding function for etc?

If not forgetting it again I'll add pow in the next days. Smiley
  

Sometimes you have to lose a fight to win the war.
Back to top
WWWICQ  
IP Logged
 
Masterkent
Developer Team
Offline



Posts: 793
Location: Russia
Joined: Apr 5th, 2013
Gender: Male
Re: Add Pow() function to Object
Reply #4 - Jan 17th, 2017 at 7:43am
Print Post  
han wrote on Jan 17th, 2017 at 1:11am:
However the basic reason for my suggestion is more an easy of use and some sort of completetion of the standard mathematical functions typically featured inside a language. Adding them has no whatsover sideeffects on any other portions of the code, while at the same time these certainly do pose a standard feature set of a language.

Unlike C/C++, UScript is not supposed to be a general purpose language, and the existing set of available standard UScript functions is limited to a small subset of potentially useful functions most of which have a more or less common use in the given particular domain. C/C++ standard libraries have a lot of functions that might be useful in some game scripts too. Hence a lot of such functions could potentially be added. The question is: when to stop? How about C/C++ functions fpclassify, isfinite, isinf, isnan, isnormal, signbit, frexp, ilogb, ldexp, modf, cbrt, hypot, erf, lgamma, tgamma, copysign, nan, nextafter, nexttoward, fdim, fma; difftime; atexit; std::swap; std::all_of, std::any_of, std::find, std::find_if, std::find_if_not, std::find_end, std::find_first_of, std::adjacent_find, std::count, std::count_if, std::mismatch, std::equal, std::is_permutation, std::search, std::search_n, std::copy, std::copy_n, std::copy_if, std::transform, std::fill, std::fill_n, std::rotate, std::random_shuffle, std::is_partitioned, std::is_sorted, std::binary_search, std::merge, std::min_element, std::max_element, std::lexicographical_compare? The list can be really long. BTW, I actually had to write analogs of std::find and std::copy for various UScript built-in dynamic arrays many times.
  
Back to top
 
IP Logged
 
han
Global Moderator
Unreal Rendering Guru
Developer Team
*****
Offline


Oldunreal member

Posts: 478
Location: Germany
Joined: Dec 10th, 2014
Gender: Male
Re: Add Pow() function to Object
Reply #5 - Jan 22nd, 2017 at 6:48am
Print Post  
For standard math functions I would draw the line after:
cos,sin,tan,acos,asin,atan,atan2,cosh,sinh,tanh,acosh,asinh,atanh,exp,log,log10,
modf,exp2,log2,pow,sqrt and fmod and a sign function would certainly be resonable too.

When it comes to UnrealScript TArray version, it should probably expose more or less the same functionality the C++ version does.
  

HX on Mod DB. Revision on Steam.
Back to top
 
IP Logged
 
Masterkent
Developer Team
Offline



Posts: 793
Location: Russia
Joined: Apr 5th, 2013
Gender: Male
Re: Add Pow() function to Object
Reply #6 - Jan 22nd, 2017 at 12:10pm
Print Post  
han wrote on Jan 22nd, 2017 at 6:48am:
For standard math functions I would draw the line after:
cos,sin,tan,acos,asin,atan,atan2,cosh,sinh,tanh,acosh,asinh,atanh,exp,log,log10,

modf,exp2,log2,pow,sqrt and fmod and a sign function would certainly be resonable too.

Probably, nobody will use even half of those functions.

Trigonometric functions, inverse trigonometric functions, square and cubic roots are sufficient for the vast majority of typical geometry problems, so I totally understand the status quo. The following functions could have useful applications

asin
atan2
cbrt
hypot (I presume, the vast majority of current uses of sqrt is computing the result of hypot)

Code
Select All
function vector MakeVector(float X, float Y, float Z)
{
	local vector Result;

	Result.X = X;
	Result.Y = Y;
	Result.Z = Z;

	return Result;
} 


Adding all hyperbolic functions, inverse hyperbolic function, and various logarithms would just result in bloating the Core.Object.

Quote:
When it comes to UnrealScript TArray version, it should probably expose more or less the same functionality the C++ version does.

The C++ version defines its functionality though member functions of std::vector, free-standing functions that operate on std::vector, and the general purpose algorithms that operate on arbitrary sequences that satisfy certain criteria. Implementing their possible equivalents for TArray would need a lot of manpower.
  
Back to top
 
IP Logged
 
han
Global Moderator
Unreal Rendering Guru
Developer Team
*****
Offline


Oldunreal member

Posts: 478
Location: Germany
Joined: Dec 10th, 2014
Gender: Male
Re: Add Pow() function to Object
Reply #7 - Feb 12th, 2017 at 11:34pm
Print Post  
Turns out, UnrealScript does in fact have a Pow:
Code
Select All
native(170) static final operator(12) float ** ( float A, float B );
 



And that it is even used a couple of times in Unreals ScriptCode.

@MK: I was refering to the C++ interface of the TArray template, not C++ STL.
  

HX on Mod DB. Revision on Steam.
Back to top
 
IP Logged
 
Masterkent
Developer Team
Offline



Posts: 793
Location: Russia
Joined: Apr 5th, 2013
Gender: Male
Re: Add Pow() function to Object
Reply #8 - Feb 13th, 2017 at 7:24am
Print Post  
han wrote on Feb 12th, 2017 at 11:34pm:
Turns out, UnrealScript does in fact have a Pow:
Code
Select All
native(170) static final operator(12) float ** ( float A, float B );
 


Ha-ha, indeed.

Quote:
I was refering to the C++ interface of the TArray template, not C++ STL.

At least, Array_Add would be a really handy extension of the current UScript interface; appending is needed quite often.
  
Back to top
 
IP Logged
 
Page Index Toggle Pages: 1
Send TopicPrint
Bookmarks: del.icio.us Digg Facebook Google Google+ Linked in reddit StumbleUpon Twitter Yahoo