More mathematical functions and double precision variables?

Started by paravantis, Mon 02/03/2009 20:27:23

Previous topic - Next topic

paravantis

AGS is amazing and tons of fun to use! I have already spent a few hours at it with my 10 year old son!

I have a rather unusual question to ask of the developers and the more experienced users. Is there any chance a fuller mathematical function set may be implemented in a future, e.g. including exp and log functions?

Also -and this is a related issue- is it at all likely that double precision variables may be implemented?

If so, AGS would be a fantastic (if somewhat unlikely) tool for educational applications, e.g. an adventure "game" into the world of high school Math or even freshman Statistics! I am salivating at dreaming of my freshmen trying to discover their way to a correct ...confidence interval!

Kindly bear with me if I am a bit off target here BUT I have been greatly excited and carried away by AGS's potential and kinda pondering about what may lie next in the adventure path...

John Paravantis
University of Piraeus
GREECE

Trent R

Haha, I like your enthusiam.

I believe there's a few Math modules around... lemme see if I can find them.
[Edit]: Dang. Seems I'm wrong... but nonetheless you can actually script a lot of math functions using AGS script. For example, this recent thread for natural logs.


~Trent
To give back to the AGS community, I can get you free, full versions of commercial software. Recently, Paint Shop Pro X, and eXPert PDF Pro 6. Please PM me for details.


Current Project: The Wanderer
On Hold: Hero of the Rune

Pumaman

There's a good chance that Log/Logn/Exp will be added to a future version.

However, it's unlikely that double-precision floating point will be added, as it's simply too specialist for a tool like AGS.

paravantis

Thank you both for responding.

Why is it such a big deal to implement double precision?

Why not drop single precision altogether and base your programming of an upcoming version on double precision floating point routines?

If I am being naive, please do forgive me. It is just that in 2009, it would seem more natural to use double precision as the default floating number type in whatever programming environment you use (C/C++ or whatever).

Nevertheless, it would be amiss if I ended my post by not thanking you for considering the implementation of exp and log functions!

With friendly regards from Greece,
John Paravantis
University of Piraeus

Pumaman

It's a big deal because the scripting engine has been written to support single-precision floating point, and not double-precision floating point. Therefore, it would need the scripting engine to be updated to support the new type and all the associated gubbins.

It's possible, of course, but it involves a fair amount of work and is not a high priority since I think you're the only person that has requested it so far.

Gilbert

As far as I remember AGS doesn't support the long integer type either. If double precision float has to be supported we need to bring in long support at the same time (actually IMO for the target types of games created with AGS long is probably more useful). I doubt whether many people really need them so I don't know if it's really worth implementing them for the time being.


Actually, personally I would want better typecasting (so we can use less IntToFloat() and FloatToInt() ) instead but I it's also fine as it is at the moment.

Dualnames

Geia sou gianni. Welcome to the AGS Forums, it's always good to see a fellow greek. Some mathematical functions are missing from AGS due to its nature and the group of people its targetting. But I must agree log and exp are a must. Abs function is really easy to script, and I'd love to hand the code to you if you care for it.
Worked on Strangeland, Primordia, Hob's Barrow, The Cat Lady, Mage's Initiation, Until I Have You, Downfall, Hunie Pop, and every game in the Wadjet Eye Games catalogue (porting)

paravantis

Dualnames, efcharisto poly for your kind words! I think I can manage coding the abs function, but if you have a snippet of code you could post, that would be great too!

Thank you all for contributing to this topic. It is too bad that coding double precision and long integers amounts to a lot of work.

I look forward to a future version that will contain a full set of (single precision) math functions.

John Paravantis

Dualnames

Quote from: paravantis on Wed 04/03/2009 14:03:56
Dualnames, efcharisto poly for your kind words! I think I can manage coding the abs function, but if you have a snippet of code you could post, that would be great too!

Thank you all for contributing to this topic. It is too bad that coding double precision and long integers amounts to a lot of work.

I look forward to a future version that will contain a full set of (single precision) math functions.

John Paravantis

function Abs(int number) {
String abs1=abs1.Format("%d,number");
if (abs1.IndexOf("-")!=-1) {
String abs2=abs1.ReplaceCharAt(0, '');
number = abs2.AsInt;
}
return number;
}

Scripted quite fast but I think it works.
Worked on Strangeland, Primordia, Hob's Barrow, The Cat Lady, Mage's Initiation, Until I Have You, Downfall, Hunie Pop, and every game in the Wadjet Eye Games catalogue (porting)

Gilbert

#9
String.Format() is static, so you don't call it using an existing String variable, and the quotes in the formating was placed wrongly.

Code: ags

function Abs(int number) {
  String abs1=String.Format("%d",number);
  if (abs1.IndexOf("-")!=-1) {
    String abs2=abs1.ReplaceCharAt(0, '');
    number = abs2.AsInt;
  }
  return number;
}


However, as IndexOf() scans the whole String for the appearance of a certain string, I'm not sure but I think it's not so economic. As the negative sign should only appear as the first entry, it's probably better to just check this. Also, I shortened something which may or may not save a bit on performance.
Code: ags

function Abs(int number) {
  String abs1=String.Format("%d",number);
  if (abs1.Chars[0]=='-') {
    abs1=abs1.ReplaceCharAt(0, '');
  }
  return abs1.AsInt;
}

Edit: Actually I'm not sure whether you can set a certain character to '' with ReplaceCharAt() to remove that character (as the manual doesn't say you can) I doubt if the codes work. Of course, you can change that '' to ' ' instead to change the negative sign to a space, which should still work with AsInt.

HOWEVER, I just don't understand, unless the AGS script engine is badly optimised for comparison of numbers (and here in particular, comparison with just 0) why would you do this in such complicated manner, with String and such? (IMO it could even be worse if you do all those String operations, either to performance and memory usage). I'd rather use the straight ahead and simple approach :P :
Code: ags

function Abs(int number) {
   if (number<0) number=-number;
  return number;
}


Dualnames

Nicely done there. Well, I always like the hard way :D :D :D
Worked on Strangeland, Primordia, Hob's Barrow, The Cat Lady, Mage's Initiation, Until I Have You, Downfall, Hunie Pop, and every game in the Wadjet Eye Games catalogue (porting)

paravantis

You guys must be just about the nicest forum I have ever bumped into!

Well, my brute force engineering/modeling background would have lead me to the

Code: ags
number=-number


approach too BUT, I must give it to Dualnames (excellent name that), the twisted way was more fun! ;D

Thanks again to all of you,
John

Dualnames

Worked on Strangeland, Primordia, Hob's Barrow, The Cat Lady, Mage's Initiation, Until I Have You, Downfall, Hunie Pop, and every game in the Wadjet Eye Games catalogue (porting)

SMF spam blocked by CleanTalk