Friday Facts #108 - Unexpected Features

Regular reports on Factorio development.
The Lone Wolfling
Long Handed Inserter
Long Handed Inserter
Posts: 97
Joined: Tue Oct 28, 2014 3:33 pm
Contact:

Re: Friday Facts #108 - Unexpected Features

Post by The Lone Wolfling »

Zeblote wrote:Maybe the smoke sprites themselves are just white and it's possible to re-color them for different things? That'd be fantastic.
Yes, although I'd kind of prefer multiple sprites to a single sprite in general.

Acius
Burner Inserter
Burner Inserter
Posts: 9
Joined: Sat Feb 07, 2015 6:49 pm
Contact:

Re: Friday Facts #108 - Unexpected Features

Post by Acius »

I just wanted to leave this here:

http://www.netlib.org/fp/dtoa.c

If you're going to write your own print formatting (printf replacement), you'll need a way to output floating point values. It probably won't surprise you that this part is harder than everything else put together! I haven't experimented to much with that link, but it is a liberally licensed method for converting floating point values to strings. It is claimed to be (1) fast and (2) accurate. If you do decide to go that way, I hope that this might help you :). I have also had to rewrite output code (in my case, I had to rewrite the C++ streams so that they would work across DLL boundaries for incompatible compiler settings), and if I hadn't been able to get sprintf working acceptably, this would have been my next resort. Good luck, those floats are a beast!

EDI
Inserter
Inserter
Posts: 21
Joined: Thu Jun 12, 2014 11:38 am
Contact:

Re: Friday Facts #108 - Unexpected Features

Post by EDI »

The new smoke graphics look totally awesome!

By the way... is there anything planned, like making the light sources (furnaces, boilers, ...) "shine through" a bit more?

cncr04s
Inserter
Inserter
Posts: 27
Joined: Wed Aug 19, 2015 3:58 pm
Contact:

Re: Friday Facts #108 - Unexpected Features

Post by cncr04s »

You should be using %f at least... not %g
Though on the other hand, if you use C++ output methods instead of C. you should run into greater compatibility across platforms.

User avatar
Gandalf
Filter Inserter
Filter Inserter
Posts: 294
Joined: Fri Dec 19, 2014 10:15 pm
Contact:

Re: Friday Facts #108 - Unexpected Features

Post by Gandalf »

Love the smoke! And the blueprint book. Release it noowwww!!1
OS: Linux Mint 19 x64 | desktop: Awesome 4.2  |  Intel Core i5 8600k  |  16GB DDR4  |  NVidia GTX 1050 Ti (driver version: 410.104)    (2019-03)

bobucles
Smart Inserter
Smart Inserter
Posts: 1645
Joined: Wed Jun 10, 2015 10:37 pm
Contact:

Re: Friday Facts #108 - Unexpected Features

Post by bobucles »

Bah, floats are way overused. Pretty much every relevant number can be best represented with an integer or decimal shifted integer. No rounding errors, no magic glitches, no weirdness at extreme ranges. Just good solid numbers from start to finish. Managing inventory values? Use an integer. Dealing with damage values? Decimal shifted integer. Time values? You bet integers are involved. Want to map out every single millimeter from the core of the sun all the way out to pluto? Yeah. That's a 64 bit integer.

The only reason to use floats is if you have a fetish for debugging that NEW STRANGE thing it's screwing up now. Also there's that whole thing about maximizing CPU registers at the ultra high end, because for some circular reason CPUs keep getting loaded with FPUs because people keep overusing floats.

User avatar
ssilk
Global Moderator
Global Moderator
Posts: 11081
Joined: Tue Apr 16, 2013 10:35 pm
Contact:

Re: Friday Facts #108 - Unexpected Features

Post by ssilk »

That's your opinion.

Mine is, that floats are really practical, if you want to measure something and keep the relative precision small.

For example, measuring distances in millimeter is nice, but when you want to measure the distance to Pluto, I doubt, that it is possible/needed, while when I want to measure the thickness of my hair it is really unpractical.

Integers can be used to COUNT stuff, not to measure.
Cool suggestion: Eatable MOUSE-pointers.
Have you used the Advanced Search today?
Need help, question? FAQ - Wiki - Forum help
I still like small signatures...

ratchetfreak
Filter Inserter
Filter Inserter
Posts: 950
Joined: Sat May 23, 2015 12:10 pm
Contact:

Re: Friday Facts #108 - Unexpected Features

Post by ratchetfreak »

bobucles wrote:Bah, floats are way overused. Pretty much every relevant number can be best represented with an integer or decimal shifted integer. No rounding errors, no magic glitches, no weirdness at extreme ranges. Just good solid numbers from start to finish. Managing inventory values? Use an integer. Dealing with damage values? Decimal shifted integer. Time values? You bet integers are involved. Want to map out every single millimeter from the core of the sun all the way out to pluto? Yeah. That's a 64 bit integer.

The only reason to use floats is if you have a fetish for debugging that NEW STRANGE thing it's screwing up now. Also there's that whole thing about maximizing CPU registers at the ultra high end, because for some circular reason CPUs keep getting loaded with FPUs because people keep overusing floats.
The hardest part with fixed point math is choosing your range and avoiding over/underflow in the temporary values. Floats will auto shift to keep as many bits as possible

ske
Filter Inserter
Filter Inserter
Posts: 394
Joined: Sat Oct 17, 2015 8:00 am
Contact:

Re: Friday Facts #108 - Unexpected Features

Post by ske »

ssilk wrote: ....
Mine is, that floats are really practical, if you want to measure something and keep the relative precision small.
....
Integers can be used to COUNT stuff, not to measure.
Deep down floats are two integers (mantissa and exponent). That is not the problem. The problem arises due to strange behavior when using floats. For example when adding three numbers a+b+c is not always equal to b+c+a. Guess what optimizing compilers do? The may change the order of operations if you don't explicitly forbid that. Also there are many different kinds of floats. IEEE754-floats, 32bit (single precision), 64bit (double precision), internal representation in x86 CPUs (80bit long double), denormalized numbers, algorithms of different accuracy (+-1bit doesn't really matter in most calculations).

Fixed point integers are like floats with a more defined beavior since you use well defined integer operations on all platforms. The downside is that you must think before calculating. How many bits do you need? What is the smallest and biggest number you need to represent? This is inconvenient but in certain situations it's better (faster, more reliable, more precise, less effort when porting to exotic architectures) than using floats.

The problem with printf is similar with fixed and floating point numbers. You are trying to represent a base-2 fractional number in base-10. It would be very easy to write the binary representation 1234*2^-12 (after all it's just two integers) but that's hard to read for humans, so the conversion to m*10^x is needed. It is not possible to do this exactly with a finite number of decimal places. You have to break off at some point (depending on the float precision) and you have to do the conversion right (considering all the rounding effects happening when you calculate the decimal places). Then when reading data you need to reassemble your floating point number from the decimal places also considering all tiny rounding effects so that no bit gets flipped everywhere for any possible number.

The Lone Wolfling
Long Handed Inserter
Long Handed Inserter
Posts: 97
Joined: Tue Oct 28, 2014 3:33 pm
Contact:

Re: Friday Facts #108 - Unexpected Features

Post by The Lone Wolfling »

ske wrote:Guess what optimizing compilers do? The may change the order of operations if you don't explicitly forbid that.
In which case the compiler is buggy. I quote:
5.1.2.3 Program execution

[#1] The semantic descriptions in this International Standard describe the behavior of an abstract machine in which issues of optimization are irrelevant.

[#3] In the abstract machine, all expressions are evaluated as specified by the semantics.

[#13] EXAMPLE 5 Rearrangement for floating-point expressions is often restricted because of limitations in precision as well as range. The implementation cannot generally apply the mathematical associative rules for addition or multiplication, nor the distributive rule, because of roundoff error, even in the absence of overflow and underflow.
There are many potential pitfalls with floats. That is not one of them (at least with sane languages). It's things like transcendental functions that are generally the problem.

sillyfly
Smart Inserter
Smart Inserter
Posts: 1099
Joined: Sun May 04, 2014 11:29 am
Contact:

Re: Friday Facts #108 - Unexpected Features

Post by sillyfly »

The implementation cannot generally apply the mathematical associative rules for addition
Interesting. That would mean that technically, in C++ an expression like:

Code: Select all

a+b+c
(where a,b,c are floats or doubles) is undefined*, and therefore should result in a compilation error, but as far as I know this it never the case.


*Explanation: Strictly speaking, expressions like a+b+c have no meaning, because + is a binary operation, acting on two, and only two terms at a time. The rule of associativity tells us that (a+b)+c = a+(b+c) (This is well defined because each + only acts on two terms), and so a+b+c can be safely assumed to be any of those two options.


Edit: If I understand correctly, either the designers of C++ or the implementers of C++ compilers chose to simply leave this as something the programmer has to keep in mind and deal with. *sigh*.

The Lone Wolfling
Long Handed Inserter
Long Handed Inserter
Posts: 97
Joined: Tue Oct 28, 2014 3:33 pm
Contact:

Re: Friday Facts #108 - Unexpected Features

Post by The Lone Wolfling »

It's... complicated:

6.5 Expressions

943 The grouping of operators and operands is indicated by the syntax.72)

951 72) The syntax specifies the precedence of operators in the evaluation of an expression, which is the same as the order of the major subclauses of this subclause, highest precedence first.

952 Thus, for example, the expressions allowed as the operands of the binary + operator (6.5.6) are those expressions defined in 6.5.1 through 6.5.6.

954 Within each major subclause, the operators have the same precedence.

955 Left- or right-associativity is indicated in each subclause by the syntax for the expressions discussed therein.

6.5.5 Multiplicative operators

1143
multiplicative-expression:
cast-expression
multiplicative-expression * cast-expression
multiplicative-expression / cast-expression
multiplicative-expression % cast-expression
The grammar indicates that a*b*c is parsed as (a*b)*c.

Of course, you have to be careful about FLT_EVAL_METHOD and FP_CONTRACT. But meh.

ratchetfreak
Filter Inserter
Filter Inserter
Posts: 950
Joined: Sat May 23, 2015 12:10 pm
Contact:

Re: Friday Facts #108 - Unexpected Features

Post by ratchetfreak »

sillyfly wrote:
The implementation cannot generally apply the mathematical associative rules for addition
Interesting. That would mean that technically, in C++ an expression like:

Code: Select all

a+b+c
(where a,b,c are floats or doubles) is undefined*, and therefore should result in a compilation error, but as far as I know this it never the case.


*Explanation: Strictly speaking, expressions like a+b+c have no meaning, because + is a binary operation, acting on two, and only two terms at a time. The rule of associativity tells us that (a+b)+c = a+(b+c) (This is well defined because each + only acts on two terms), and so a+b+c can be safely assumed to be any of those two options.


Edit: If I understand correctly, either the designers of C++ or the implementers of C++ compilers chose to simply leave this as something the programmer has to keep in mind and deal with. *sigh*.
It's very well defined in the operator priority rules actually (left to right).

Any optimization that would use floating point associativity is typically opt-in with a -fastmath flag to the compiler.

Silden
Inserter
Inserter
Posts: 44
Joined: Thu Sep 10, 2015 3:59 pm
Contact:

Re: Friday Facts #108 - Unexpected Features

Post by Silden »

DOSorDIE wrote:...and of course with a option to deactivate.
+1

Jaridan
Inserter
Inserter
Posts: 21
Joined: Tue Dec 30, 2014 2:54 pm
Contact:

Re: Friday Facts #108 - Unexpected Features

Post by Jaridan »

One thing that came to mind after seeing the "Blueprint Book" was, if you could implement a "Repair Bag" or something alike, where all items go to that you pick up and are damaged, since those cannot (atm) be stacked in an inventory and it is a bit frustrating that "damaged" entities can easily take up a lot of space in your inventory.

The Lone Wolfling
Long Handed Inserter
Long Handed Inserter
Posts: 97
Joined: Tue Oct 28, 2014 3:33 pm
Contact:

Re: Friday Facts #108 - Unexpected Features

Post by The Lone Wolfling »

Jaridan wrote:One thing that came to mind after seeing the "Blueprint Book" was, if you could implement a "Repair Bag" or something alike, where all items go to that you pick up and are damaged, since those cannot (atm) be stacked in an inventory and it is a bit frustrating that "damaged" entities can easily take up a lot of space in your inventory.
Or just a way to queue repairs for things in your inventory...

User avatar
Karosieben
Long Handed Inserter
Long Handed Inserter
Posts: 58
Joined: Sun Aug 31, 2014 9:21 pm
Contact:

Re: Friday Facts #108 - Unexpected Features

Post by Karosieben »

I like the new smoke. :)

Also this blueprint books looks really nice. Would be handy for my Season 2 :D

Keep going, guys. Factorio gets better and better!
My german YouTube Channel: Karosieben
My Factorio Let's Plays: Singleplayer, Multiplayer and Tutorials

ske
Filter Inserter
Filter Inserter
Posts: 394
Joined: Sat Oct 17, 2015 8:00 am
Contact:

Re: Friday Facts #108 - Unexpected Features

Post by ske »

ratchetfreak wrote: It's very well defined in the operator priority rules actually (left to right).

Any optimization that would use floating point associativity is typically opt-in with a -fastmath flag to the compiler.
In this case I stand corrected.

What I remember though is that excess precision may still be an issue and -ffloat-store must be used on x86:
manual page of gcc wrote:

Code: Select all

-ffloat-store
    Do not store floating point variables in registers, and inhibit other options that might change whether a floating point value is taken from a register or memory.

    This option prevents undesirable excess precision on machines such as the 68000 where the floating registers (of the 68881) keep more precision than a double is supposed to have. Similarly for the x86 architecture. For most programs, the excess precision does only good, but a few programs rely on the precise definition of IEEE floating point. Use -ffloat-store for such programs, after modifying them to store all pertinent intermediate computations into variables. 

Xerrass
Burner Inserter
Burner Inserter
Posts: 19
Joined: Mon Oct 05, 2015 12:11 pm
Contact:

Re: Friday Facts #108 - Unexpected Features

Post by Xerrass »

#betterSmokeInFactorio

yago2003
Burner Inserter
Burner Inserter
Posts: 10
Joined: Fri Sep 25, 2015 5:00 pm
Contact:

Re: Friday Facts #108 - Unexpected Features

Post by yago2003 »

I hasn't broken any of the mods i have, (except 1, the clock from bobs mods), but something really annoying is that all the names of stuff say entity:name:name of thing instead of the normal name, can u fix it soon, because its really annoying, and waiting an entire week seems like soooooooo long, also before friday facts came out on friday like at 1 pm, now the come out at like 1 am.... of the next day, Please Fix, thumbs up for the smoke graphics

Post Reply

Return to “News”

Who is online

Users browsing this forum: Alice3173, conn11, valneq