Page 6 of 8

Re: issue-#124 Range-check for SHORT(ENTIER(real))

Posted: Thu Aug 25, 2016 9:11 am
by Robert
Still not happy about MOD.

1 - The same thing (about from the very obvious difference) occurs for both INTEGER & LONGINT, so it is less confusing to describe it using the same wording.
2 - INTEGER. "The low bits of the correct answer are returned". This is confusing; all the correct answer is returned (I think!).
3 - LONGINT. "MOD is range checked, and overflows ...". Again confusing; it does not need range checking, and overflows cannot occur.

Re: issue-#124 Range-check for SHORT(ENTIER(real))

Posted: Thu Aug 25, 2016 11:58 am
by Josef Templ
MOD can indeed be removed from that section. It never produces an out-of-range value.

> 2 - INTEGER. "The low bits of the correct answer are returned". This is confusing; all the correct answer is returned (I think!).

MAX(INTEGER) * MAX(INTEGER), e.g., produces a value larger than INTEGER
but not the full answer is returned. This was correct.

For the diff see http://redmine.blackboxframework.org/pr ... 0988269fc4.

I also replaced 'correct answer' by 'result'. Sounds less negative to me.

- Josef

Re: issue-#124 Range-check for SHORT(ENTIER(real))

Posted: Thu Aug 25, 2016 12:16 pm
by Robert
Josef Templ wrote:MAX(INTEGER) * MAX(INTEGER), e.g., produces a value larger than INTEGER
but not the full answer is returned. This was correct.
Misunderstandings are so easy! I meant it was confusing in the context of MOD. Of course it is correct for the other procedures.

Anyway, I am happy with the current text.

Re: issue-#124 Range-check for SHORT(ENTIER(real))

Posted: Thu Aug 25, 2016 2:24 pm
by Robert
Josef Templ wrote:As far as I know this (ie real arithmetic rounding) is very much the same as in C.
A college has just run my example in Microsoft Visual Studio 2010 C. BlackBox is significantly different and (in my opinion) much better.

Notes:
1 - C & C# behave the same as each other.
2 - Both C & C# behave differently depending if the target application is a 32 or 64 bit application. Who would have guessed that?

Re: issue-#124 Range-check for SHORT(ENTIER(real))

Posted: Fri Aug 26, 2016 7:36 am
by luowy
Robert wrote: A college has just run my example in Microsoft Visual Studio 2010 C. BlackBox is significantly different and (in my opinion) much better.
the BB's result can be produced easily by a c compiler

Code: Select all

#include <stdio.h>
// #include <math.h>

int main(int argc, char** argv){
    float  a, b, c, s, t, u, x, y;
    
    __asm
    {
        
        push	830   ;33EH
        fldcw [esp]
                pop ecx
    }
    
    /* //gcc
    asm("pushl $830");
    asm("fldcw (%esp)");
    asm("popl %ecx");
    */
    
    a = 10000000.;
    b = 3.0;
    c = 3333333.0;
    x = a * (a / b - c) - c;                  //(* Correct to 5 / 5 digits *)
    printf("%.16f\n", x);
    
    s = a / b;
    t = s - c;
    u = a * t;
    y = u - c;                                // (* Correct to 2 / -6 digits *)
    
    printf("%.16f\n", y);                  //(*  Correct to 7 digits  *)
    
    return 0;
}
this control word make some simple expression like Math.Pi() == Math.Pi() get a FALSE result(like BB),
will confuse normal users. so most compiler select float64 as default(internal) precision.

c & c# compiler, are industry products,heavily optmized and updated for modern cpu,
BB compiler cant compete with them in many aspects.

luowy

Re: issue-#124 Range-check for SHORT(ENTIER(real))

Posted: Fri Aug 26, 2016 8:14 am
by Robert
luowy wrote:What result does the C compiler give us? I prefer C standard.
I assumed that you were talking about "Default" compiler settings. I am not surprised that you can use Assembler to change things, you can do that in BlackBox also - and I do!. There are probably (Microsoft, gcc, ?) compiler options that enable changed behaviour even without using Assembler.

My points are:
- The phrase "C standard" does not allow us (me ?) to easily and unambiguously know precisely what you mean
- and we may not want to do the same anyway.

Your final result shows that the gcc optimiser is making significant rearrangements to the code, which (here) makes it much more accurate, and probably significantly faster.
Do we want such optimisation in BlackBox? - I think there is no point thinking about the answer because we can't afford to implement it even if we did.

Your comment: "confuse normal users" - I couldn't agree more!

Re: issue-#124 Range-check for SHORT(ENTIER(real))

Posted: Fri Aug 26, 2016 8:21 am
by cfbsoftware
Robert wrote: A college has just run my example in Microsoft Visual Studio 2010 C. BlackBox is significantly different and (in my opinion) much better.
Is there a reason why you have written the example in this way? I would have written it as:

Code: Select all

  a := 10.0;
  b := 3.0;
  c := 3.0;
  x := a * (a / b - c) - c; 
  ...
  ...
On .NET with REALs this results in:

x: 0.33333333333333481
y: 0.33333333333333481

This was using GPCP for .NET but I would expect identical results for C# as your example gave identical results for GPCP and C#.

Re: issue-#124 Range-check for SHORT(ENTIER(real))

Posted: Fri Aug 26, 2016 8:49 am
by Robert
Firstly there is a typo in the bottom line of my .pdf: for "C(#)32" read "C(#)64".
cfbsoftware wrote:Is there a reason why you have written the example in this way? I would have written it as:
That is a different question, and leads to a different answer. No surprise there. I chose my particular example as it emphasises the differences, but I could have chosen many other examples.

I'm sorry, but I don't really understand your post, in particular the two "identicals" in the last line.
Are you comparing:
- Your example with mine
- GPCP with BlackBox
- REALs with SHORTREALs
- In-line with non in-line source code
- WIN32.exe with WIN64.exe?

Maybe it would be clearer to me if you gave a table of your actual results.

Cheers

Re: issue-#124 Range-check for SHORT(ENTIER(real))

Posted: Fri Aug 26, 2016 9:34 am
by Josef Templ
I have recreated the topic branch for issue-#100 because it had such a long list of minor updates.
Now it is in one commit.

For me this is ready for voting.

- Josef

Re: issue-#124 Range-check for SHORT(ENTIER(real))

Posted: Fri Aug 26, 2016 12:43 pm
by cfbsoftware
Robert wrote:I'm sorry, but I don't really understand your post
Just ignore what I said. I now understand that I misunderstood your post :(