Angband Forums 4.0.5 device skill effect
 Register FAQ Members List Calendar Search Today's Posts Mark Forums Read

 January 14, 2017, 12:10 #11 PowerWyrm Veteran     Join Date: Apr 2008 Posts: 2,303 http://angband.oook.cz/forum/showpos...&postcount=177 I was pretty sure that was fixed in 4.0.4, but apparently not... __________________ PWMAngband variant maintainer - check http://powerwyrm.monsite-orange.fr (or http://www.mangband.org/forum/viewforum.php?f=9) to learn more about this new variant!
January 19, 2017, 19:01   #12
kandrc
Swordsman

Join Date: Dec 2007
Posts: 281
Quote:
 Originally Posted by Pondlife If both sides of that division are integer, you'll end up with integer division. That's rarely what you want (e.g. 10/3 = 3). I'd normally force something to be float or double, e.g: final *= (100.0 + context->boost) / 100.0; Note that I know nothing about the Angband source; so I may well be talking out of my backside. But I've been burnt by integer division in C before so I thought I'd mention it.
Floating point is sloooooowwwwww. 10s (or on some architectures even 100s) of cycles of latency, versus one cycle of latency for integer. Roguelikes have enough complicated stuff going on that this actually does matter. It's easy to end up with a compute-bound roguelike game simply by using floating point.

Today's processors are fast enough that you could get away with expressions like the above here and there, but back in the day it would have made the game unplayable. Maintainers have made the wise decision (whether or not they understood it (no implication intended)) to stick with an integer only design philosophy, thus avoiding painful FP creep.

If your integer division gives you unacceptable rounding errors, the solution is not to convert to float; it's to multiply all numerator terms by 10 (or 100, or whatever value gives you enough decimal places) and treat it as fixed point.

January 19, 2017, 19:15   #13
Derakon
Prophet

Join Date: Dec 2009
Posts: 8,205
Quote:
 Originally Posted by kandrc Floating point is sloooooowwwwww. 10s (or on some architectures even 100s) of cycles of latency, versus one cycle of latency for integer. Roguelikes have enough complicated stuff going on that this actually does matter. It's easy to end up with a compute-bound roguelike game simply by using floating point.
This might have been the case way back in the day when Angband was first written, but is really not the case any more. Certainly it is possible to make a slow roguelike by making unwise choices, but it's not going to be because you decided to use floating-point math instead of fixed-point, it's going to be because you decided to have hundreds of units all running A* pathfinding every turn, or because you're using software rendering to draw thousands of letters, one at a time, every time any aspect of the screen changes. Dumb algorithmic decisions are what will wreck you, not dumb formulaic decisions.

And the problem with the "just avoid floating point" mindset is that now every single computation you do, you have to worry about whether you're screwing things up. It's easy to introduce bugs like the above. If you just let yourself use floats then things get a lot simpler.

As always, obey these rules of optimizing:

* Is it slow? If not, don't optimize.
* Figure out what part is slow.
* Measure how slow it is.
* Optimize that part.
* Measure it again.

Optimizing almost always sacrifices clarity of code for efficiency of code, and it always results in more work being spent on a given piece of code that's otherwise functional. These are both substantial costs, so you should only optimize when it proves to be necessary.

That doesn't mean that you shouldn't be aware of broad-scale runtime implications, of course. Don't use bubble sort, that kind of thing. But your #1 concern for your code should always be does it do the right thing? Code that provides the wrong answer is worse than useless; code that is correct but slow is merely annoying.

 January 19, 2017, 19:50 #14 Pete Mack Prophet   Join Date: Apr 2007 Location: Seattle, WA Posts: 4,454 Donated: \$40 Or you can just do final += final* boost/100 like any other normal integer calculation.
January 19, 2017, 20:25   #15
Nick
Vanilla maintainer

Join Date: Apr 2007
Location: Canberra, Australia
Age: 52
Posts: 6,960
Donated: \$60
Quote:
 Originally Posted by Derakon This might have been the case way back in the day when Angband was first written, but is really not the case any more. Certainly it is possible to make a slow roguelike by making unwise choices, but it's not going to be because you decided to use floating-point math instead of fixed-point, it's going to be because you decided to have hundreds of units all running A* pathfinding every turn, or because you're using software rendering to draw thousands of letters, one at a time, every time any aspect of the screen changes. Dumb algorithmic decisions are what will wreck you, not dumb formulaic decisions.
You are, of course, correct in principle, although at this point in its development starting to use floating point in Angband would be a great source of bugs. There's also the consideration that we don't know for sure exactly what architecture the game will "need" to run on in the future. So it will be staying integer only for now.
__________________
One for the Dark Lord on his dark throne
In the Land of Mordor where the Shadows lie.

January 19, 2017, 20:42   #16
Derakon
Prophet

Join Date: Dec 2009
Posts: 8,205
Quote:
 Originally Posted by Nick You are, of course, correct in principle, although at this point in its development starting to use floating point in Angband would be a great source of bugs. There's also the consideration that we don't know for sure exactly what architecture the game will "need" to run on in the future. So it will be staying integer only for now.
Yeah, my screed was more meant to apply to anyone considering starting a new project. Legacy code will always have weird quirks that made sense at the time and that aren't worth the hassle of trying to bring "up to date".

January 19, 2017, 22:05   #17
AnonymousHero
Veteran

Join Date: Jun 2007
Posts: 1,331
Quote:
 Originally Posted by Nick There's also the consideration that we don't know for sure exactly what architecture the game will "need" to run on in the future. So it will be staying integer only for now.
Heh. I don't think it's particularly likely that there'll be many new platforms without (at least emulated) floating point . Doesn't C89 actually mandate floating point support?

 January 20, 2017, 13:18 #18 Rydel Apprentice   Join Date: Jul 2008 Posts: 81 I think it's less an issue of new platforms, and more of someone deciding that's it's vital that Angband be ported to their Commodore VIC-20... assuming that port doesn't already exist. __________________ I'm trying to think of an analogy, and the best I can come up with is Angband is like fishing for sharks, and Sil is like hunting a bear with a pocket knife and a pair of chopsticks. It's not great. -Nick
January 20, 2017, 16:57   #19
PowerDiver
Prophet

Join Date: Mar 2008
Posts: 2,712
Quote:
 Originally Posted by Rydel I think it's less an issue of new platforms, and more of someone deciding that's it's vital that Angband be ported to their Commodore VIC-20... assuming that port doesn't already exist.
That's what compilers are for.

 January 20, 2017, 19:34 #20 Pete Mack Prophet   Join Date: Apr 2007 Location: Seattle, WA Posts: 4,454 Donated: \$40 Sure, floating point has it's place. But in this case, it really is fundamentally an integer operation. I posted the correct arithmetic earlier. No, you do not want to add first then multiply. Multiply first then add.

 Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 Thread Tools Display Modes Linear Mode

 Posting Rules You may not post new threads You may not post replies You may not post attachments You may not edit your posts BB code is On Smilies are On [IMG] code is On HTML code is Off Forum Rules
 Forum Jump User Control Panel Private Messages Subscriptions Who's Online Search Forums Forums Home Angband     AAR     Vanilla     Development     ToME     Sil     Variants     Competition The real world     Idle chatter     Oook! Obsolete     v4

 Similar Threads Thread Thread Starter Forum Replies Last Post Ingwe Ingweron Variants 2 November 17, 2014 06:11 Stone Dog Sil 2 December 8, 2013 23:04 Old Coach v4 1 January 23, 2012 22:05 UglySquirrell Variants 2 October 14, 2011 03:06 dhegler Vanilla 3 May 21, 2010 20:36

All times are GMT +1. The time now is 05:02.