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

The features that we decide to not apply in the current time
User avatar
Robert
Posts: 1024
Joined: Sat Sep 28, 2013 11:04 am
Location: Edinburgh, Scotland

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

Post 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.
User avatar
Josef Templ
Posts: 2047
Joined: Tue Sep 17, 2013 6:50 am

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

Post 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
User avatar
Robert
Posts: 1024
Joined: Sat Sep 28, 2013 11:04 am
Location: Edinburgh, Scotland

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

Post 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.
User avatar
Robert
Posts: 1024
Joined: Sat Sep 28, 2013 11:04 am
Location: Edinburgh, Scotland

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

Post 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?
Attachments
Floats2.pdf
BlackBox vs C arithmetic precision
(40.7 KiB) Downloaded 288 times
luowy
Posts: 234
Joined: Mon Oct 20, 2014 12:52 pm

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

Post 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
User avatar
Robert
Posts: 1024
Joined: Sat Sep 28, 2013 11:04 am
Location: Edinburgh, Scotland

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

Post 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!
cfbsoftware
Posts: 204
Joined: Wed Sep 18, 2013 10:06 pm
Contact:

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

Post 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#.
User avatar
Robert
Posts: 1024
Joined: Sat Sep 28, 2013 11:04 am
Location: Edinburgh, Scotland

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

Post 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
User avatar
Josef Templ
Posts: 2047
Joined: Tue Sep 17, 2013 6:50 am

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

Post 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
cfbsoftware
Posts: 204
Joined: Wed Sep 18, 2013 10:06 pm
Contact:

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

Post 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 :(
Post Reply