Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
A simplier math formula
Message
From
16/12/2008 01:02:44
Lutz Scheffler
Lutz Scheffler Software Ingenieurbüro
Dresden, Germany
 
 
To
15/12/2008 18:41:51
General information
Forum:
Politics
Category:
Other
Miscellaneous
Thread ID:
01367448
Message ID:
01367734
Views:
7
>>>>>-2**2
>>>>>
>>>>>what the answer... I lost my bet with my secondary schoolgirl daughter... :(
>>>>4
>>>
>>>VFP says 4 but online math calculator, my math. eng. friend and my daughter say -4... :(
>>
>>Probably it has been said already as I am not following the thread, but -2**2 = -2*-2 =4
>
>Nope: -2**2 is the same as -1*2**2 so, by order or precedence, the answer is -4.
>
>See http://mathforum.org/library/drmath/view/69058.html

BOK

Hi Alan,

Folks I'm upset.

This is not the unary operator.

The minus is just our representation for a negative number. -2 is just the number -2 not the negative of 2. It's just luck that the operation -1*2 returns -2.

so if you write
a=-2
?a^2
there is no question about the result.

This problem is something bound to the numbering system we use. We are bound to the idea that we have 2, (8), 10, 16 as base for our numbering system. In this system - an unary operator makes some sense.

But if you use a negative as base, things get clearer

think about a base of -2

so we get (parenthesis only for accuracy)
Base -2 = Base 10
0 = 0
1 = 1  && n^0 is 1
10 = -2 && (-2)^1 = -2
11 = -1 && (-2)^1+(-2)^1 = (-2)+1
100 = 4 && (-2)^2 = (-2)*(-2)=4
so you see the term 10 represents -2 decimal. If you square this you square the number -2. There is no need for a negative sign.

Same is with integers in comps

You know

we have (4 bit)
Binary = decimal
0001 = 1
0010 = 2
0011 = 3
..
0111 = 7
but
Binary = decimal
1111 = -1
1110 = -2
so there is no question about the square of 1110?

For the problem
-a^2 
I agree with you that the operation is
-(a^2)
because a is some number and - is unary operator.

Agnes

Update:

Ok. there seems to be the mad scientist have decided to need parenthesis in this case. I'm 100% that we have done this different in school and university. I realy like things like that that end up in usless arguments with the teachers
They simply should invent a new sign to distinct negative numbers from unary operator.

We will end up with a new keyborad layout just to enter all those parenthesis (and a language that supports square bracket and curly brackets so get an idea what where we are).

So this a sign that we should not use literals or constants. A variable shout return the expected value.

And yes, vfp returns wrong value for -a^2

Agnes
Words are given to man to enable him to conceal his true feelings.
Charles Maurice de Talleyrand-Périgord

Weeks of programming can save you hours of planning.

Off

There is no place like [::1]
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform