Jump to content

Photo

Question about integers


  • Please log in to reply
10 replies to this topic

#1 Avaro

Avaro

    >w<

  • Members

Posted 24 May 2013 - 01:25 PM

I have a question about integers. And I am talking about the "int abc = 0;" part at the top of a script file, wich can be changed by a script.

When playing the quest, I realise that when you save, ZC also saves the current values of the integers. I wonder if there is a limit on how many integers I can use for my quest? The sav. file can't be infinitely big, can it?

 

Second question. Integers can be used for soo many things, for example: a game time counter that counts the seconds. Is there a limit on how big the value of an integer can be? If I set that "counter" to count every second, would there be a limit? And what would happen if it reached that limit, does it stop increasing, or does it reset to 0 or to a negative number (can integers have negative numbers? what about decimals?), or would ZC crash? Is there even a limit?



#2 Soga

Soga

    Secretly Alive

  • Members

Posted 24 May 2013 - 02:54 PM

You can have up to about 256 global variables. Global array variables count as one.

 

When an integer variable reaches its maximum value 214748, adding one will cause it to wrap around to the smallest negative number (-214748). Decimals work similarly. Subtracting one from that negative number, likewise, wraps it back to the maximum positive value.


  • ShadowTiger likes this

#3 Avaro

Avaro

    >w<

  • Members

Posted 24 May 2013 - 03:10 PM

Okay, thanks! It's good to know how many of these integers I can use. About the values, any idea how the strange limit of "214748" came off? :lol:

I'm glad its such a high number, anyways. And I didn't know I can even use such small negative numbers too.



#4 grayswandir

grayswandir

    semi-genius

  • Members

Posted 24 May 2013 - 04:43 PM

 Actually, the highest value should be  (2^31)-1 = 214747, instead. The negative limit is still -(2^31) = -214748.

In depth: http://en.wikipedia....wo's_complement

Basically, 214747 is 0111111..., and -214748 is 100000... in the machine.


Edited by grayswandir, 24 May 2013 - 04:51 PM.


#5 Soga

Soga

    Secretly Alive

  • Members

Posted 24 May 2013 - 05:12 PM

grayswandir: I got that number from http://www.purezc.ne...showtopic=38176



#6 grayswandir

grayswandir

    semi-genius

  • Members

Posted 24 May 2013 - 06:00 PM

Oh, I haven't seen that before...

 

...

 

So yeah, my math was wrong, but it's still the same reason. It goes from -(2^31) = -2147483648 to (2^31)-1 = 2147483647, they just divide by 10,000 after.

 

...

 

Why does zscript call them floats if they're not actually floating-point numbers? :angry:


Edited by grayswandir, 24 May 2013 - 06:19 PM.


#7 SUCCESSOR

SUCCESSOR

    Apprentice

  • Banned
  • Real Name:TJ

Posted 30 May 2013 - 06:01 PM

Why does zscript call them floats if they're not actually floating-point numbers? :angry:

 

Actually they are floating point numbers. int is the misnomer.

 

Q: Assembly only had floats. What is the difference between the types "int" and "float"? What about "bool"?

A: There is no difference whatsoever between float and int; both are synonymous and provided as a convenience. Functions that take ints happily accept floats, and vice-versa. Moreover, unlike C, there is no implicit truncation of ints; in the following snippet
int x = 1/2;
the value of x becomes 0.5, not 0.

Bools are represented internally as in C: 0 is false, anything else represents true. However, like in C++, bools and ints are NOT interchangeable; you can't add two bools, and should not assign a bool to a variable of type int. However, ints are safely and implicitly cast as bools.

 

Source


Edited by SUCCESSOR, 30 May 2013 - 06:05 PM.


#8 grayswandir

grayswandir

    semi-genius

  • Members

Posted 30 May 2013 - 06:54 PM

Numbers go to four decimal places and have a range of -214748.3648 to 214748.3647.

 

No, there's no floating point to be seen there. That is quite clearly a fixed point. int isn't really a misnomer here, because you're treating them like integers. (Well, you would be if it truncated them for you. But it's still kinda somewhat useful? Maybe?)  But at no point are you treating them like floats. If you were, you could write float a = INFINITY, for example.

 

http://en.wikipedia....oint_arithmetic

http://en.wikipedia..../Floating_point


Edited by grayswandir, 30 May 2013 - 07:00 PM.


#9 Gleeok

Gleeok

    It's dangerous to dough alone, bake this.

  • Members
  • Real Name:Pillsbury
  • Location:Magical Land of Dough

Posted 30 May 2013 - 09:01 PM

Yep.

From my understanding scripts originally had, or were going to have, floats for a tiny short time, but were gotten rid of for some reason. Probably because ZC uses a lot of fixed numbers since it was originally a Z1 clone.

Actually they are floating point numbers. int is the misnomer.


The 0.5 is actually a long.

445123245_total_recall_bulge_eyes_300_xl

#10 SUCCESSOR

SUCCESSOR

    Apprentice

  • Banned
  • Real Name:TJ

Posted 30 May 2013 - 11:29 PM

LOL. I get what y'all be sayin'! I will be honest my understanding of floating point numbers is fuzzy. What I meant was that both float and int are the same in ZC. My misunderstanding of the post I responded to was brought about by me skimming through scripting posts as I tend to do when I lurk PureZC.

I learned something about ZC. I don't know how useful it is but I did learn.

Edited by SUCCESSOR, 30 May 2013 - 11:33 PM.


#11 Soga

Soga

    Secretly Alive

  • Members

Posted 30 May 2013 - 11:55 PM

Yeah, it's probably worth pointing out to newbies that if they want to use ints like actual proper red-blooded American ints, they need to perform integer truncations themselves with Floor() for operations that may return a decimal value. Otherwise, they get very strange results.




1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users