News:

MASM32 SDK Description, downloads and other helpful links
MASM32.com New Forum Link
masmforum WebSite

FPU compare real to integer problem

Started by RuiLoureiro, March 17, 2012, 01:36:34 PM

Previous topic - Next topic

raymond

Which all leads to the conclusion that, if you write an expression starting with a "-" sign, use brackets to clarify the expression. Otherwise, it risks being misinterpreted.
When you assume something, you risk being wrong half the time
http://www.ray.masmcode.com

dioxin

qWord,
Quotemake this sense?
Yes, perfect sense.
All real, positive numbers have 2 real square roots which differ only in sign.
sqrt(9) = +3 and -3 since (+3)*(+3) = 9 and (-3)*(-3) = 9.

Paul.

dedndave

well - a little reading...
it appears there are "differing conventions" between mathematicians and programmers using various languages
so - Excel, C, etc - noone is "wrong", per se   :P
the same can be said of the "/" symbol, for example, 1/2X may be read 2 ways
as Raymond pointed out, use parens if needed

i never realized there were "differing conventions"
still learn something new everyday - lol
good to know and be aware of

qWord

Quote from: dioxin on March 21, 2012, 02:30:45 AM
qWord,
Quotemake this sense?
Yes, perfect sense.
All real, positive numbers have 2 real square roots which differ only in sign.
indeed, this was a weak example.
However, for 'common' algebra, -x^2 is treated as -(x^2).
If there are calculator or solvers, that do not follow this, then they do this probably because of technically reasons (like my SmplMath-macros)

qWord
FPU in a trice: SmplMath
It's that simple!

dioxin

qWord,
Quotethen they do this probably because of technically reasons
The reason the calculator does it is because it was considered the correct way for it to be done, not because of some technicality which couldn't be avoided.

Paul.

RuiLoureiro

Paul,
        I have no time to discuss rules and logic problems.
        I have a lot of things to do in the next few days.
       
        In any way raymond told one general rule when we write
        one expression:
        «if you write an expression starting with a "-" sign,
        use brackets to clarify the expression»

        But you dont answer my question:

        What do you mean if you write this: +9-3^2 ?

one note:   1. sqrt(9) = 3
                 2. If we are solving the equation x^2-9=0
                  the solutions are: x1=+3, and x2=-3
Quote
    -3^2 means (-3)^2 not -(3^2)

        Folowing your own rules, we have:
       
        (a)     -(+3)^2 = (-3)^2= (-3)*(-3)= 9
        (b)     -(-3)^2 = (+3)^2= (+3)*(+3)= 9
        (c)     +(+3)^2 = (+3)^2= (+3)*(+3)= 9
        (d)     +(-3)^2 = (-3)^2= (-3)*(-3)= 9

        Its beautiful ! It seems we are in the Zeta space

one note more:

From Wikipedia you can read:

«Exceptions to the standard»

«There exist differing conventions concerning the unary operator -
(usually read "minus").
In written or printed mathematics, the expression -3^2 is interpreted to mean -(3^2) = -9,
...?»

        I repeat to you (as i taught this things a lot of years ago)

        In mathematics -3^2 is interpreted to mean -(3^2) = -9.

dioxin

Rui,
QuoteBut you dont answer my question:
        What do you mean if you write this: +9-3^2 ?
I did answer it. The - in that case is a binary operator and has the same precedence as +. It's the unary minus which causes problems.


QuoteFolowing your own rules, we have:

        (a)     -(+3)^2 = (-3)^2= (-3)*(-3)= 9
        (b)     -(-3)^2 = (+3)^2= (+3)*(+3)= 9
        (c)     +(+3)^2 = (+3)^2= (+3)*(+3)= 9
        (d)     +(-3)^2 = (-3)^2= (-3)*(-3)= 9

No we don't! As soon as you separate the - from the number that follows it then it ceases to be part of that number.
   -3^2 = 9      'the - is part of the number minus3, it's not a separate entity from the digit 3
   -(3)^2 = -9    'the - is not part of any number but becomes an operator on the result of the bracketed expression


   So we actually get:
        (a)     -(+3)^2 =  -(3)^2 = -(3*3)    = -9
        (b)     -(-3)^2 = -(-3)^2 = -(-3*-3)  = -9
        (c)     +(+3)^2 = (+3)^2  = (+3)*(+3) = 9
        (d)     +(-3)^2 = (-3)^ 2 = (-3)*(-3) = 9



Quoteone note more:
From Wikipedia you can read:
«Exceptions to the standard»

I think the one clear thing that has been established here is that there is no standard.
It's not just me versus everyone else. There are significant other sources which do it the way I say.

Paul




RuiLoureiro

Paul,
        1. Ok, i dont want to follow that rules of unary minus or whatever.  :wink
       
        2. I usually doesnt use Wikipedia. But as we can see there,
           «In mathematics -3^2 is interpreted to mean -(3^2) = -9.»

        3. What is the problem ? On your first post, you said:
           «no it isn't». It means that your interpretation is
           correct and the others are incorrect or dont exist.
           It is a question of rules.
       
Quote
There are significant other sources which do it the way I say.

        4. and significant other sources which doesnt follow it.

        5. Well, what are the rules ?
           This:

            The order of operations, or precedence (used throughout mathematics,
            science, technology and many computer programming languages) is:

            1. terms inside parentheses or brackets
            2. exponents and roots
            3. multiplication and division
            4. addition and subtraction

            I dont change that rules now. In this way

            if we write 1+2^3*2/3, calcula20 start with 2^3 then *, /, +

            More: it we type 2^3^4, calcula20 starts by the end: 3^4

RuiLoureiro

qWord,

-3^2 = (-3)*(-3) = 3^2
-3^2 = 3^2 ???
make this sense?

            No. To me it doesnt.

The same to     -3^2+9 = 9+9 = 18       
               but     9-3^2 = 9-9 = 0        (we lost the commutativity)

         If x=-3^2 stands for a real number and y=9 is another real number
         then x+y=y+x (commutativity law).

qWord

RuiLoureiro,

Quote from: RuiLoureiro on March 21, 2012, 07:19:35 PM
            The order of operations, or precedence (used throughout mathematics,
            science, technology and many computer programming languages) is:

I'm right there with you.
FPU in a trice: SmplMath
It's that simple!

RuiLoureiro

#85
qWord,
        Ok !  :U  :wink
       
Hi all !

        Calcula21, now solves some more cases that calcula20 doesnt solve.
       
        Remember that:
                        -X^Y  means this  -(X^Y)

       
        Now, we have:       e^x = EXP(x) = exp(x)
        To get e=2.718...   e^1

        Good luck !
        Did you note some errors ?
        Please tell me !
        Thanks

        note: cases like: (-2)^(-5/3) ... (-2)^(2/3) ...

        note: it can solve up to 200 operatios in each (...)
              and we can write 200 (...)

        Calculation rules

            1. terms inside parentheses or brackets
            2. functions
            3. exponents or powers
            4. multiplication and division
            5. addition and subtraction

        a) All calculatios are made in 80 bit format
           e.g.: 2+3    both are taken as real10 numbers
           
        b) Exceptions: expressions X^Y. Y is taken as integer32
                       if possible;
                       
           e.g.: (-2)^(2+3*1/3-1) but not here (-2)^(2+3*1/3-1.0)
                 because one term is 1.0


dedndave

35 Kb EXE file
16 Kb of it is 0's   :bg
you could use uninitialized data for a lot of it
but, alas, we cannot see the source   :(

RuiLoureiro

Quote from: dedndave on March 22, 2012, 07:27:47 PM
35 Kb EXE file
16 Kb of it is 0's   :bg
you could use uninitialized data for a lot of it
but, alas, we cannot see the source   :(
Dave,
        read again the post.
        May be i solve that problem in Calcula22 !

dedndave

well - i couldn't find any problems with Calcula20   :P

RuiLoureiro

#89
Dave,
Quote
well - i couldn't find any problems with Calcula20   

        With calcula20:
       
---------------------------------------------
Type an expression and press enter [ ex: -pi + 3.1*(7 - 2*8.3) ]
(-2)^(3/5)
This is your expression: (-2)^(3/5)
This is your Result:  ERROR
(-2)^(3/5)=ERROR
---------------------------------------------

Quote
35 Kb EXE file
16 Kb of it is 0's   

        Now calcula22 has 19.5K. I used uninitialized data.
        I dont know if i alloc mem it isnt shorter

***
        I found one error in Calcula21.
        It is solved in calcula22.

        Thanks
EDIT:
Sorry, i failled using fcomip  st(0),st(1)
and the result was allways 0 ! It is solved
The problem is to remove -0.00000