Friday Facts #35 The lighthouse keeper

Regular reports on Factorio development.
Alfdaur
Long Handed Inserter
Long Handed Inserter
Posts: 72
Joined: Sat Mar 08, 2014 10:41 am
Contact:

Re: Friday Facts #35 The lighthouse keeper

Post by Alfdaur »

kovarex wrote:the release is planned for friday, lets see what can we do :)
O yeah! Let's hope for a quick delivery!
muzzy
Fast Inserter
Fast Inserter
Posts: 187
Joined: Sat Nov 23, 2013 7:17 am
Contact:

Re: Friday Facts #35 The lighthouse keeper

Post by muzzy »

kovarex wrote:Right now, I'm writing my own trigonometric functions, so yes I'm kind of deep in kind of nonsense :)
http://stackoverflow.com/questions/2387 ... lculations
You should never have to write your own trigonometry functions :D

Googling about it a little finds this, although I haven't used it myself ... http://lipforge.ens-lyon.fr/www/crlibm/

PS. Are you using the same compiler for windows build too? If you're using MSVC, you might want to verify that you have floating point optimization mode set to fp:precise instead of fp:fast, and there might be other eventual inconsistencies with floating point accuracy due to differences in instruction sets used by the different compilers (i.e. one compiler might be using more accurate SSE registers and rounding to double).
kovarex
Factorio Staff
Factorio Staff
Posts: 8207
Joined: Wed Feb 06, 2013 12:00 am
Contact:

Re: Friday Facts #35 The lighthouse keeper

Post by kovarex »

The reason why I'm writing this is not to get better precision, it is not needed at all.
The reason is, that the result of sin/cos/asin/acos/atan etc. are different on different platforms, and I need the results to be exactly the same to achieve determinism.
darkweaver
Manual Inserter
Manual Inserter
Posts: 4
Joined: Sat Sep 28, 2013 6:20 pm
Contact:

Re: Friday Facts #35 The lighthouse keeper

Post by darkweaver »

kovarex wrote:The reason why I'm writing this is not to get better precision, it is not needed at all.
The reason is, that the result of sin/cos/asin/acos/atan etc. are different on different platforms, and I need the results to be exactly the same to achieve determinism.
hi,
why don't you use lookup tables to get an approximate value ?
User avatar
ssilk
Global Moderator
Global Moderator
Posts: 12889
Joined: Tue Apr 16, 2013 10:35 pm
Contact:

Re: Friday Facts #35 The lighthouse keeper

Post by ssilk »

Hm. I have just discussed this problem with a fellow, which is doctor in physics. He said for that type of problem those libraries are not a good choice, cause everything, which was formerly calculated on the FPU in one CPU-cycle is now calculated on the CPU in hundreds of cycles. He said, this is needed for other problems, but for a game it would be a killer.

We had no good idea about that. But we found some aspects, which might be worth thinking:

- Where is this problem relevant? I mean it is only relevant, if you have a floating point number, which is a result of some calculation from some operation, which has a big difference in it's dimensions. The result depends in that case very much on how you do the operation. This is a deep field in science (numerology, measuring etc.). So eventually in some cases some different algorithm works better. If this problem can be reduced to only some cases, it could be also a solution to calculate in two steps or with more precision.

- How did that others? I mean Starcraft had the same problem. And many other games, too. Or did they just replaced all calculations with integer calculations? :)

- A nearly equivalent problem is for example calculations in a sound program. I'm not sure, but I think in Propellerheads Reason, they have something, which enables them to make exactly the same calculation of a sound over and over. How do they those calculations for a simulated DSP? They need to do it, cause Reason for example calculates with 32 bit floating point!

@darkwater:
The idea sounds clever. But the problem is not that, cause sinus works in most cases still a bit like that. The problem, as I see it, is the calculation of longer formulas. Every single step needs to be rounded. And now, depending on, how/in which order such a formula is solved, the result differs. This is quite normal. And with step I don't mean just +, -, * etc. A step is for example calculation if the result is positive or negative, cause from that it depends, how the next step works.
Cool suggestion: Eatable MOUSE-pointers.
Have you used the Advanced Search today?
Need help, question? FAQ - Wiki - Forum help
I still like small signatures...
pbhead
Inserter
Inserter
Posts: 43
Joined: Mon Apr 21, 2014 5:45 am
Contact:

Re: Friday Facts #35 The lighthouse keeper

Post by pbhead »

As far as I know, the best way to make sure everything is the same across all platforms is to remove all floating point calculations.
Flux Faraday
Long Handed Inserter
Long Handed Inserter
Posts: 66
Joined: Sat May 10, 2014 8:48 am
Contact:

Re: Friday Facts #35 The lighthouse keeper

Post by Flux Faraday »

darkweaver wrote:why don't you use lookup tables to get an approximate value ?
This is a very good suggestion. The tables don't have to be large since you don't care about precision (say 1/10 of a degree per entry, use symmetry to shrink tables further). It will also be way less of a drain on processor resources than computing a truncated taylor series.
starxplor
Fast Inserter
Fast Inserter
Posts: 164
Joined: Sun May 18, 2014 11:25 pm
Contact:

Re: Friday Facts #35 The lighthouse keeper

Post by starxplor »

It used to be that computing was always better than memory op's, however this is changing as storage(specifically cache running similar to CPU clock) increases speed while human perception and interface remains relatively constant.

I wonder if/when CPUs will start allowing processes to load such lookup tables when the writer of the program can say that computations always fall into a static set of inputs. This could be especially nice for branching controls, allowing even shorter circuiting of predictive processing when wrong and having to jump...

Sorry this is all a bit off-topic, heh.
Noro
Burner Inserter
Burner Inserter
Posts: 17
Joined: Fri Dec 13, 2013 2:14 pm
Contact:

Re: Friday Facts #35 The lighthouse keeper

Post by Noro »

Can't you just make calculations with some reserve and after every calculation step cut off last digits to some level of guarantied precision? Maybe you'll get less final precision that you want but this way you can safely use FPU methods.
kovarex
Factorio Staff
Factorio Staff
Posts: 8207
Joined: Wed Feb 06, 2013 12:00 am
Contact:

Re: Friday Facts #35 The lighthouse keeper

Post by kovarex »

Noro wrote:Can't you just make calculations with some reserve and after every calculation step cut off last digits to some level of guarantied precision?
This looks like easy solution, but it is not correct actually.

Logically whatever kind of rounding you use, you are basically assigning group of numbers to other numbers. But you will always have borders, where one number (in computer floating point terms) belongs to one group, while the number next to it belongs to different group, which means, that even small lack of precision can change the result of rounded results.

The example is
You get the result 0.9999999999 on one system and 1.0 on the other. The difference is 0.0000000001, but when I round both to lets say 0.1 precision, I still get 0.9 versus 1.0.
WiduX
Burner Inserter
Burner Inserter
Posts: 8
Joined: Mon May 19, 2014 5:39 am
Contact:

Re: Friday Facts #35 The lighthouse keeper

Post by WiduX »

You get the result 0.9999999999 on one system and 1.0 on the other. The difference is 0.0000000001, but when I round both to lets say 0.1 precision, I still get 0.9 versus 1.0.
Wouldn't that technically be truncating (0.999 -> 0.9), instead of rounding (0.999 -> 1.0)? The terminology is similar, but there is quite a difference.

Although I might be completely wrong :/
Gammro
Filter Inserter
Filter Inserter
Posts: 361
Joined: Wed Oct 09, 2013 1:45 pm
Contact:

Re: Friday Facts #35 The lighthouse keeper

Post by Gammro »

You're right, but Kovarex was replying to noro, who talked about "cutting off" digits.
Ignore this
kovarex
Factorio Staff
Factorio Staff
Posts: 8207
Joined: Wed Feb 06, 2013 12:00 am
Contact:

Re: Friday Facts #35 The lighthouse keeper

Post by kovarex »

WiduX wrote:
You get the result 0.9999999999 on one system and 1.0 on the other. The difference is 0.0000000001, but when I round both to lets say 0.1 precision, I still get 0.9 versus 1.0.
Wouldn't that technically be truncating (0.999 -> 0.9), instead of rounding (0.999 -> 1.0)? The terminology is similar, but there is quite a difference.

Although I might be completely wrong :/
The same logic can be applied also to rounding, it is also division of the set of double numbers to smaller set, just the examples of border numbers are different.


0.049999999999999
versus
0.05

One will be rounded to 0.0, the other one to 0.1, difference is again only 0.0 (...) 1
Stilgar84
Manual Inserter
Manual Inserter
Posts: 1
Joined: Thu May 29, 2014 10:21 pm
Contact:

Re: Friday Facts #35 The lighthouse keeper

Post by Stilgar84 »

I would also try some kind of precomputed table. I did some experiment and using linear interpolation between point would require two constants at 5610 points to approximate sin and cos at 1e-8 (taking symmetry into account). This would probably not be very cache friendly especially if several additional functions are needed.

I tried with second order polynomial (a+b*x+c*x*x) and we only need 150 points or less (I didn't seek the optimal coefficients) with tree constants each to achieve the same level of precision. this may be a good compromise.

I made a small IJulia notebook with graph comparing those two approaches and taylor series expansion: https://dl.dropboxusercontent.com/u/176 ... 81%29.html (warning, it is quick and dirty and my first use of julia)

a similar approach could be taken for the other needed function. for tan, I would use asymptotic approximation when x -> pi/2. For atan, when x>threshold, can also use an asymptotic approximation.

Obviously, the choice of approach depend on if you really need 1e-8 precision, if you need to have continuous derivative or not in which case cubic spline may be better.
therapist
Fast Inserter
Fast Inserter
Posts: 177
Joined: Tue May 27, 2014 7:22 pm
Contact:

Re: Friday Facts #35 The lighthouse keeper

Post by therapist »

I'm losing my mind hitting the refresh button. It's friday. It's friday. It's friday. It's friday. It's friday. IT IS FRIDAY. DO IT. DO IT NOW.

edit: If someone has knowledge of the 0.10.0 release date being pushed back further than today, for the love of god put me out of my misery.

Image
Tami
Fast Inserter
Fast Inserter
Posts: 157
Joined: Tue Nov 19, 2013 11:29 am
Contact:

Re: Friday Facts #35 The lighthouse keeper

Post by Tami »

It looks like the developer as fallen asleep before pressing the "press" button xD
FrozenOne
Fast Inserter
Fast Inserter
Posts: 177
Joined: Mon Mar 04, 2013 8:10 pm
Contact:

Re: Friday Facts #35 The lighthouse keeper

Post by FrozenOne »

As many bugs were marked as fixed in the last hours, i'd say devs have not yet given up the race.
Trucario
Long Handed Inserter
Long Handed Inserter
Posts: 77
Joined: Fri Aug 09, 2013 12:40 pm
Contact:

Re: Friday Facts #35 The lighthouse keeper

Post by Trucario »

therapist wrote:I'm losing my mind hitting the refresh button. It's friday. It's friday. It's friday. It's friday. It's friday. IT IS FRIDAY. DO IT. DO IT NOW.

edit: If someone has knowledge of the 0.10.0 release date being pushed back further than today, for the love of god put me out of my misery.

Image


+1276713 :geek:
User avatar
SpaceMushroom
Burner Inserter
Burner Inserter
Posts: 5
Joined: Wed May 21, 2014 8:05 pm
Contact:

Re: Friday Facts #35 The lighthouse keeper

Post by SpaceMushroom »

therapist wrote:I'm losing my mind hitting the refresh button. It's friday. It's friday. It's friday. It's friday. It's friday. IT IS FRIDAY. DO IT. DO IT NOW.

edit: If someone has knowledge of the 0.10.0 release date being pushed back further than today, for the love of god put me out of my misery.
This!!! Awaiting deployment :P
FishSandwich
Smart Inserter
Smart Inserter
Posts: 1847
Joined: Sun Feb 23, 2014 3:37 pm
Contact:

Re: Friday Facts #35 The lighthouse keeper

Post by FishSandwich »

therapist wrote:I'm losing my mind hitting the refresh button. It's friday. It's friday. It's friday. It's friday. It's friday. IT IS FRIDAY. DO IT. DO IT NOW.

edit: If someone has knowledge of the 0.10.0 release date being pushed back further than today, for the love of god put me out of my misery.

Image
Feel your pain, I was really looking forward to it today. It is now Saturday morning where I live, hopefully it'll be out when I wake up. Eager to do a video on it.
Post Reply

Return to “News”