i don’t know what I was thinking while making the game… I just collected garbage. I used bad ways like adding 0.001 and round it when needed. There where many ways to do that. In a rush i picked this
If int overflows use Long. if you write “int number = 3000000000” (3 billion), you will get error or negative value since it will turn into garbage.
If you use “long number = 3000000000L” it will be okay, you can go as high as 8-9 quintillion, if I remember right. (9.000.000.000.000.000.000)
https://msdn.microsoft.com/en-us/library/ctetwysk.aspx (Don`t forget to put “L” after the number, as you put “f” after float)
If negative numbers don’t make sense for whatever you’re doing, using uint instead of int may help. This will actually double the max value before it would rollover to 0.
Well what is your suggestion for displaying a number that has over a thousand digits?
Look at all of you posting reasonable answers. Why can’t people dream of having numbers in their games with as many digits as there are characters in Artamène ou le Grand Cyrus?
[quote=“Wrymnn, post:22, topic: 579183, username:Wrymnn”]
If you use “long number = 3000000000L” it will be okay, you can go as high as 8-9 quintillion, if I remember right. (9.000.000.000.000.000.000)
[/quote]
Pff look at that scrub number. It only has 19 digits.
I think a better question is, under what circumstances do you have to?
There’s certainly no reason a monster needs to have 27,000,000,000,000 health.
What’s the point when you’re simply going to throw away precision beyond seven digits?
You don’t have to if it’s all stored as a string It will slow your program down considerably if you were operating on the values in real time, but it’s doable!
Hey, maybe I only made that initial suggestion so I could in the end take a shot at blizzard for having monsters with more than 27,000,000,000 health in diablo 3. Did you consider that? :3
I must say it feels wonderful to have so many people say it’s poor design. I like when developers screw up the IP they’ve taken from other developers. The Activision-blizzard south-WoW team has no business with ARPGs, especially the diablo series.
–edit
Don’t tell me it doesn’t make you feel superior to computers when you can write out 1,000,000,000,000,000,000,000,000,000,000
- 1,000,000,000,000,000,000,000,000,000,000
= 2,000,000,000,000,000,000,000,000,000,000
but a computer cannot
Well, I think in Wow:Mists of Pandaria some bosses had such a huge numbers due to fact that blizzard was always increasing stats from Vanilla.
Actually there is. To show how much badass your character is to give like 100,000,000,000 damage while fight being of reasonable length (i.e. enemy doesn’t die in 2 hits).
Tell that to Blizzard!
I have a suspicion that they may be faking it. You can’t change your equipment in Greater Rifts where these absurd numbers are, so there’s a chance they might scale everything down and pad some random text onto the end.
Talking of use cases, idle games are the most common use I’ve seen for high precision numbers. It actually becomes quite common to add a vey small number to a very large one there.
Many noobs jump on Unity thinking idle games have to be the easiest to make, then run into issues with data precision or overflow.
In the last WoW expansion they did the logical thing and wound everything back to smaller numbers. 1,000,000 became 10,000 etc. It was still at the same level it initially was because everything was scaled back, it was just a significantly smaller and more optimized number.
Displaying a string number is fine, but doing string splits/parsing etc seems ott. Its a fun solution no doubt, but every string operation is added overhead (trivial amount sure… but its still there).
I get the feeling it’s that most people who were more recently self-taught don’t get a lesson on data structures. It’s something most people who went to school understand pretty well, so they don’t actually talk about it, which leaves people who were self-taught not knowing that variables are finite.
Working with string made a difference of my program running for 3 seconds vs it running for 34 minutes. With all of the logging information off it ran almost instantly. I didn’t even log anything until it finished, it just added log information to an array of strings and then saved it at the end.
In java, string anything seems to delay things significantly.
Maybe. But maybe not.
I’m self taught. One of the early things I did was read through the MSDN documentation on each of the primitive types. Its pretty apparent what the data limitations are from a quick skim. Sure I don’t remember the limits, but I know they are there if I ever need them. I would have approached this problem by first reading the documentation on int.
Maybe its just my training in chemical engineering. Maybe its my religious background. But reading the manual is pretty deeply ingrained in me. As is a distrust in an infinite container. If I can’t build a tank that holds an infinite amount of liquid, why should a computer be any different.
I’m also old enough to remember the Y2K bug, where every computer in the world was brought to its knees because the early programmers decided to only include two digits of precision on dates. So maybe anyone younger then 20 does have an excuse for not to have an in built appreciation for the limitations of data types.
Edit: And lets hope that our grand kids remember to fix this before the year 10,000 messes it all up again.
27,000,000,000,000 could be stored as 27,000 * 1,000,000,000.
You have int, uint, long, ulong - if you need more than that, I’d argue you’re doing something wrong.
I remember y2k, and how it was a completely blown out of proportion. Great time to be a dev though, and it was a great way to force old redundant systems to be updated.
I can’t imagine most people start with MSDN references. I tend to think the wording is overly technical (granted it’s never technical enough when you need it), and it’s easy to get lost in parts that aren’t what people actually use.
I would imagine people usually start with tutorials that just say “this is for integers, this is for decimals, and this is for letters” and aren’t given much understanding of what they are and how they work. It won’t be until they get bit in the ass by it that they really start to understand how it all works.