Thank you for trying Fog-Framework and welcome to the mailing list.
I can confirm that your code produces the assertion. It was a bug and
it was fixed. I found another bug related to the GradientD, so
updating to trunk is really necessary.
Now I'd like to do small correction to your code:
This:
GradientD gradient( GRADIENT_TYPE_LINEAR );
gradient._pts[0] = PointD(x,y);
gradient._pts[1] = PointD(50.0, 50.0);
List<ColorStop> colorstops;
colorstops += ColorStop(0.0f, Argb32(0xFFFFFF00));
colorstops += ColorStop(1.0f, Argb32(0xFFFF0000));
gradient.setStops( colorstops );
Pattern pattern( gradient );
painter.setSource( pattern );
could be replaced by:
LinearGradientD gradient(PointD(x, y), PointD(50.0, 50.0));
gradient.addStop(0.0f, Argb32(0xFFFFFF00));
gradient.addStop(1.0f, Argb32(0xFFFF0000));
painter.setSource( gradient );
Using underscores in Fog-Framework in production code should be
minimized, with underscore are usually decorated private members and
functions.
Thank you for the report!
Best regards
Petr Kobalicek
please try to rebuild project completely to avoid the crash; I
experienced that visual studio creates wrong build when changed core
files (I'm not sure about other compilers).
If the problem remains I will check it.
I noticed the locale problem too, this will be fixed soon. But this
should affect nothing, because Fog is using unicode versions of
WinAPI.
Thanks
Petr
I updated the compiler error issue and I can reproduce the png saving
bug (using GDI+). I'm going to fix it,
Thank you!
Petr
GDI+ codec is now fixed;)
Best regards
Petr
the code is right :) There are binary ops, but it's only here to make
sure that compiler will emit only one condition per function. The &&
and || will of course work too.
Thanks for review;)
Best regards
Petr Kobalicek
On Tue, Dec 13, 2011 at 11:52 PM, Jacques Leroy <blake...@hotmail.com> wrote:
> I keep finding it strange...
>
> generally:
>
> ((2) && (1)) is 3 , so true
>
> ((2) & (1)) is zero == false
>
Actually this is not the case, because result of comparison (a op b)
should be always 0 or 1, so bitwise ops should do the right job. I
need more testing whether this way has benefit or not, but generally
I'd like to tell compiler that one cmp/branch is okay for the whole
comparison.
> and I can't see optimized code using bitwise operators ...
It probably depends on the compiler/arch, I think that there should be
benefit at least for ARM, we will see in the future;)
Best regards
Petr
I understand the differences between & and &&, and I currently want to
evaluate both conditions. The reason is that some processors, for
example ARM, have many conditional instructions, and such code can
execute using only one conditional branch, which is the most costly
instruction, if mispredicted.
But what I don't understand is your example, mainly "if (condition1 &
condition2) evaluates to (1 & 2) = (01 & 10)". I don't know whether
the condition can evaluate to a different value than 0 or 1, so this
shouldn't never be an issue. If you know about compiler / architecture
where the expression like a > b, or a == b, or a < b, etc can evaluate
to a different value than 0, 1, and to be more precise, where
expressions like (a > b) and (a < b) can evaluate to a different
non-zero values on 'true', then post me a link so I can read about the
possible issues.
I'm currently making port for ARM devices, so I will be able to test
(a > b) & (c > d) against (a > b) && (c > d). I use & mainly when it
comes into floating point, because I'm sure that compiler is unable to
optimize && to & when working with float/double types.
Hope that my explanation is clear ;)
Best regards
Petr Kobalicek
if (*(int*)&f1 < *(int*)&f2)
works perfectly !
(but don't know if it brings any benefit with ARM architecture...)
Friendly yours,
Jacques Leroy
I know that article, I read it more times, because I wanted to have
float comparison done right in Fog. But there are always limitations
when making comparison using integers, as you said, they must be
strictly positive, for example. So currently I'm not using such tricks
to compare floats (only Hash<float, X> can compare floats using binary
representation).
But back to your question about using & and | in conditions. There is
no much code where this technique is used and this technique is only
used in very strict way. I said that the idea behind it is strictly an
optimization, telling compiler that I'd like to compare more
variables, but I'd like to use only one branch.
for example, if I have two integers, and I need to do some comparison,
then there is no much difference between using & vs &&. I think that
compiler can emit & instead of && automatically - and I'm sure that
Intel compiler does it.
Example:
int a, b;
int x, y;
1) if ((a == x) && (b == y)
vs
2) if ((a == x) & (b == y)
For me 1) is more readable, 2) should be faster in the most
architectures, but I hope that C++ compilers do the right job, so
personally I don't care about this scenario.
But if we substitute int using float, for example:
float a, b;
float x, y;
1) if ((a == x) && (b == y))
vs
2) if ((a == x) & (b == y))
Then compiler can't simply use & instead of && if not mentioned,
because there can be signaling nan in 'b' or 'y' and in such case 1)
would be okay, but in 2) an exception should be thrown. This is the
main reason why & is sometimes used when working with floating point.
If you browse the whole Fog code then you shouldn't find that using
single & is only in some places and there is reason for it. There is
no dangerous code such ((a != NULL) & (a[0] != 0)) as you wrote in the
previous post.
I'd like also to mention that bit masking is used extensively in
SSE/SSE2 code, so using & is basically the same, but done in C - and
used carefully;)
Best regards
Petr Kobalicek