Author Topic: Rounding up to n decimal places?  (Read 2118 times)

0 Members and 1 Guest are viewing this topic.

Offline Pete

  • Forum Resident
  • Posts: 2361
  • Cuz I sez so, varmint!
Re: Rounding up to n decimal places?
« Reply #15 on: February 05, 2021, 10:48:53 pm »
708. No idea how many of those are blank lines for code readability. 36 KB size on disk.

Pete
Want to learn how to write code on cave walls? https://www.tapatalk.com/groups/qbasic/qbasic-f1/

Offline madscijr

  • Seasoned Forum Regular
  • Posts: 295
Re: Rounding up to n decimal places?
« Reply #16 on: February 06, 2021, 01:51:22 pm »
Still, I just stick with strings when it comes to math. That's only limited by system memory.

My only question would be, what about performance?
If it's just a calculation here and there, that's one thing.
But if you're say, trying to round numbers from game controller input at least 30 frames a second (per controller) as well as whatever graphics and game logic are going on, will the string conversion overhead result in a noticable lag in the responsiveness of the game?
I don't know the answer, just asking. I know people might say, if you need speed that badly, program in C or C++, but for my purposes at least, QB64 is fast enough, but I'm still in the beginning stages with QB64 and using it to make games, and haven't gotten to the point yet where I have had to worry about lags!

Offline Pete

  • Forum Resident
  • Posts: 2361
  • Cuz I sez so, varmint!
Re: Rounding up to n decimal places?
« Reply #17 on: February 06, 2021, 02:28:45 pm »
Ah, you are programming in C/C++. That's the language QB64 translates your BASIC code into. In other words, QB64 is a translator.

I doubt you would need huge numbers in gaming, so whatever the fastest method is would be the best choice. There are little speed testing programs you can use. Mark and Steve have made quite a few of those.

I mean for me, on a fairly slow system, this happens almost instantaneously...

Code: QB64: [Select]
  1. FOR i = 1 TO 100000
  2.     j = j + .1
  3. PRINT "Hello world.", i, j

It also shows how computers can't count, without a coded system of counting.

So if 10 conditions were used with a string math calculation, I suppose you could estimate a performance of a 1 to 10 thousand digit number being calculated in a very short amount of time. Over kill for business apps, great for scientific apps, and I don't do gaming, so I have no experience to offer an opinion on adequate speed over some alternate method, in that regard.

Pete
Want to learn how to write code on cave walls? https://www.tapatalk.com/groups/qbasic/qbasic-f1/

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
Re: Rounding up to n decimal places?
« Reply #18 on: February 06, 2021, 04:36:23 pm »
Yes, for game performance regular type numbers in QB64 are much more practical.

Only resort to string math when you want say, factorials over 50! or division to 1000 places, extreme math stuff.