replace var with float and support var as float typedef

Posted By: HeelX

replace var with float and support var as float typedef - 08/13/10 20:02

Hi JCL,

can you please consider to abandon the var type soon? I don't think it is a big deal! Just replace everywhere var with float and create a backward compatibility through

typedef float var;

You can also replace all integer values with the int type (like panel coordinates) and savely use it since you automatically convert floats to int, right?

I think this is NOT such a big deal, isn't it?

Thanks in advance,
-Christian
Posted By: JibbSmart

Re: replace var with float and support var as float typedef - 08/13/10 21:10

Seconded! Most of my headaches in anything motion/physics related comes from the fact that VECTORs are composed of vars.

Jibb
Posted By: Lukas

Re: replace var with float and support var as float typedef - 08/13/10 21:33

Dunno if this is so easy with backwards compatibility (because of precision and stuff, the "advantage" of vars is that is can exactly store numbers like 1000000.5), but otherwise I'd agree, too.

But, replacing panel coordinates and sizes with ints is kindof tricky, because if you set it to 0, it has the size of its bitmap, while it vanishes if you set it to 0.1. And I think there are some other issues like that with vars that normally could be ints...
Posted By: DJBMASTER

Re: replace var with float and support var as float typedef - 08/13/10 21:53

Thirded (even a word? lol)

I'd like lite-c to just stick with int and float instead of var.
Posted By: Quad

Re: replace var with float and support var as float typedef - 08/13/10 21:55

fourthed(im sure thats not a word :d)

i always use floats my self but as others it would be great if predefined structs also use float.
Posted By: Macro

Re: replace var with float and support var as float typedef - 08/13/10 22:06

Fifthed.

I prefer to work with standard c data types where I can.

MACRO
Posted By: Superku

Re: replace var with float and support var as float typedef - 08/13/10 22:09

What's so bad about var?
Posted By: ChrisB

Re: replace var with float and support var as float typedef - 08/13/10 22:10

I support this request too. My religion forbids the use of fixed point variables and I dont want to go to hell just for using acknex.
Posted By: Lukas

Re: replace var with float and support var as float typedef - 08/13/10 22:15

Originally Posted By: Superku
What's so bad about var?

This might give you some idea:
http://www.opserver.de/ubb7/ubbthreads.php?ubb=showflat&Number=294389&page=2

What bugs me personally the most, is that I can't even exactly store a value of e.g. 0.1, because it get's converted to 102/1024 = 0.099609375.
Posted By: JibbSmart

Re: replace var with float and support var as float typedef - 08/13/10 22:29

Originally Posted By: Superku
What's so bad about var?
If you've ever worked with Quaternions, you lose a horrendous amount of precision by using vars. This is because of all the trigonometry that gets used. The vec_ functions would be so much more useful if VECTORs were composed of floats. It's not the end of the world to write my own versions that use floats, but it's annoying.

Jibb
Posted By: Saturnus

Re: replace var with float and support var as float typedef - 08/13/10 23:19

var is also impractical when it comes to vector calculations. Calculating dot products for example is only possible with small-magnitude vectors. This is indeed somewhat annoying. I neather want to typecast between float and var all the time, nor I want to use my own vector functions. AFAIK converting floating point numbers to integer types in C is (or was) for some reason a pretty slow process on Pentium machines. I don't know whether this still applies to lite-C, though.

However, Gamestudio has the reputation of being a program with very good backward compatibility. Replacing var with float will easily break this backward compatibility completely. var is not only used for fixed point numbers, but also for storing engine object handles and pointers. Entity skills are vars, too. So replacing alone won't do it.

Even though I would appreciate a change-over to standard C data types, I consider "abandoning the var type soon" unlikely at the moment. Might be a wrong estimate, though.
Posted By: JibbSmart

Re: replace var with float and support var as float typedef - 08/14/10 00:25

I wonder how realistic it would be to ask for a #define, then, that enabled the switch?

Jibb
Posted By: FlorianP

Re: replace var with float and support var as float typedef - 08/14/10 04:07

definitely agree!
Never in history something was as unecessary as inventing the var-type.
Posted By: HeelX

Re: replace var with float and support var as float typedef - 08/14/10 07:47

Originally Posted By: Saturnus
Replacing var with float will easily break this backward compatibility completely. var is not only used for fixed point numbers, but also for storing engine object handles and pointers. Entity skills are vars, too. So replacing alone won't do it.


Float was just a suggestion because var's are used most often for numeric stuff. If you only have integer values - use integer. If you return pointers, return them in the appropriate format or use simply void* (e.g. for sound handles or do typedef void* SOUND_HANDLE or else).
Posted By: Tobias

Re: replace var with float and support var as float typedef - 08/14/10 10:02

Vars must be replaced with double, not float. Replacing them with float would lose precision with large numbers, so thats the opposite of what you want. But I think double will work for all coordinate ranges without losing precision.

It wont be backwards compatible of course, but rewriting scripts for double vars should be not to difficult. Sometimes it could be tricky but in most cases the vars only need to be replaced with int, or with pointers, depending on what you do with them.

Its similar to the step from C-Script to lite-C.
Posted By: ventilator

Re: replace var with float and support var as float typedef - 08/14/10 11:06

with floats you don't need that big numbers though since they are much better suited for directly using them as (much more intuitive) meters instead of 32 quants = 1 meter, or 1 quant is 1 inch or something like that.

but if i remember correctly lite-c doesn't really fully support floats anyway (my memory about this is fuzzy but didn't a lot of stuff always require casting to double?) so doubles would be fine too. laugh
Posted By: jcl

Re: replace var with float and support var as float typedef - 08/18/10 14:43

You would not like it when we replaced var with floats, and let you then deal with lots of problems like reduced precision, failing of comparison operations and so on. Rewriting your scripts would be a nightmare, much worse than the rewriting WDL code to C. Vars will stay.

But using floats and doubles for vector and matrix operations makes a lot of sense and you're free to do that - the whole DirectX vector and matrix library can be used with lite-C. The function list can be found in the DirectX documentation. The DirectX functions are sometimes even faster than their vec_ counterparts.
Posted By: Lukas

Re: replace var with float and support var as float typedef - 08/18/10 15:00

Ok, that makes some sense. But could you at least overload some functions, that internally cast the vars to other types anyway, such as e.g. file_asc_write, where char would make much more sense?
Posted By: jcl

Re: replace var with float and support var as float typedef - 08/19/10 10:06

All C languages automatically convert numbers and numerical variables. You don't need overloading for this.
Posted By: Lukas

Re: replace var with float and support var as float typedef - 08/19/10 11:52

I know, but it kind of feels wrong to take a char, cast it to var, and then cast it back to char. This is also a small performance loss.
© 2024 lite-C Forums