Page 3 of 4

Re: Friday Facts #108 - Unexpected Features

Posted: Sat Oct 17, 2015 2:20 pm
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.

Re: Friday Facts #108 - Unexpected Features

Posted: Sat Oct 17, 2015 5:43 pm
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!

Re: Friday Facts #108 - Unexpected Features

Posted: Sat Oct 17, 2015 6:45 pm
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?

Re: Friday Facts #108 - Unexpected Features

Posted: Sat Oct 17, 2015 8:07 pm
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.

Re: Friday Facts #108 - Unexpected Features

Posted: Sun Oct 18, 2015 2:03 am
by Gandalf
Love the smoke! And the blueprint book. Release it noowwww!!1

Re: Friday Facts #108 - Unexpected Features

Posted: Sun Oct 18, 2015 3:45 am
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.

Re: Friday Facts #108 - Unexpected Features

Posted: Sun Oct 18, 2015 6:23 am
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.

Re: Friday Facts #108 - Unexpected Features

Posted: Sun Oct 18, 2015 11:29 am
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

Re: Friday Facts #108 - Unexpected Features

Posted: Sun Oct 18, 2015 12:32 pm
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.

Re: Friday Facts #108 - Unexpected Features

Posted: Sun Oct 18, 2015 3:34 pm
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.

Re: Friday Facts #108 - Unexpected Features

Posted: Sun Oct 18, 2015 3:44 pm
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*.

Re: Friday Facts #108 - Unexpected Features

Posted: Sun Oct 18, 2015 4:29 pm
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.

Re: Friday Facts #108 - Unexpected Features

Posted: Sun Oct 18, 2015 4:34 pm
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.

Re: Friday Facts #108 - Unexpected Features

Posted: Sun Oct 18, 2015 5:13 pm
by Silden
DOSorDIE wrote:...and of course with a option to deactivate.
+1

Re: Friday Facts #108 - Unexpected Features

Posted: Sun Oct 18, 2015 8:06 pm
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.

Re: Friday Facts #108 - Unexpected Features

Posted: Sun Oct 18, 2015 8:38 pm
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...

Re: Friday Facts #108 - Unexpected Features

Posted: Mon Oct 19, 2015 10:38 am
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!

Re: Friday Facts #108 - Unexpected Features

Posted: Mon Oct 19, 2015 11:23 am
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. 

Re: Friday Facts #108 - Unexpected Features

Posted: Mon Oct 19, 2015 12:45 pm
by Xerrass
#betterSmokeInFactorio

Re: Friday Facts #108 - Unexpected Features

Posted: Mon Oct 19, 2015 1:24 pm
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