negative decimal issues

View: New views
12 Messages — Rating Filter:   Alert me  

negative decimal issues

by Adam de Zoete-2 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

I'm having a bit of decimal math issues. A far as i'm aware setting a
negative decimal negative should give me a positive decimal.

I've produced a type below to demonstrate the issue.

define_type('setneg',
        -description='Test to set a negative value');
       
        local('input') = decimal;
        local('newdecimal') = decimal;
       
        define_tag('oncreate',
                -required='input');
               
                self -> 'input' = #input;

        /define_tag;
       
       
        define_tag('process');
       
                self -> 'newdecimal' = -(self -> 'input');
                self -> 'input' > 0
                        ? return('A positive decimal of ' + self -> 'input' + ' should have a
negative value of ' + self -> 'newdecimal')
                        | return('A negative decimal of ' + self -> 'input' + ' should have a
positive value of ' + self -> 'newdecimal');
       
        /define_tag;
       
/define_type;


var('test') = setneg(1.27);
$test -> process;

/* => A positive decimal of 1.27 should have a negative value of -1.27
(CORRECT) */


var('test') = setneg(-1.27);
$test -> process;

/* => A negative decimal of -1.27 should have a positive value of -1.27
(INCORRECT) */


Am I declaring this wrong or is it a bug?

If I set it to:

self -> 'newdecimal' = 0-(self -> 'input');

I get a correct answer, but most calculators will do this math for you!

Many thanks,

Adam

--
This list is a free service of LassoSoft: http://www.LassoSoft.com/
Search the list archives: http://www.ListSearch.com/Lasso/Browse/
Manage your subscription: http://www.ListSearch.com/Lasso/



Re: negative decimal issues

by Douglas Burchard :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

On Nov 5, 2009, at 10:53 AM, Adam de Zoete wrote:

> I'm having a bit of decimal math issues. A far as i'm aware setting  
> a negative decimal negative should give me a positive decimal.
>
> I've produced a type below to demonstrate the issue.

...snip...

> self -> 'newdecimal' = -(self -> 'input');

Why don't you try writing this as:

                (self -> 'newdecimal') = ((self -> 'input') * (-1));


--
Douglas Burchard, President
DouglasBurchard.com, Web Applications
15024 NE 66th Street
Redmond, WA  98052, USA

direct: (206) 227-8161
solutions@...
http://www.douglasburchard.com/




--
This list is a free service of LassoSoft: http://www.LassoSoft.com/
Search the list archives: http://www.ListSearch.com/Lasso/Browse/
Manage your subscription: http://www.ListSearch.com/Lasso/



Re: negative decimal issues

by Adam de Zoete-2 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Douglas Burchard wrote:

> On Nov 5, 2009, at 10:53 AM, Adam de Zoete wrote:
>
>> I'm having a bit of decimal math issues. A far as i'm aware setting a
>> negative decimal negative should give me a positive decimal.
>>
>> I've produced a type below to demonstrate the issue.
>
> ...snip...
>
>>         self -> 'newdecimal' = -(self -> 'input');
>
> Why don't you try writing this as:
>
>         (self -> 'newdecimal') = ((self -> 'input') * (-1));

Yes, that's the better method. I was assuming that Lasso would
understand the negative assignment as other applications do.

MacBook-Pro:~ adam$ echo "-(-1.27)" | bc
1.27

mysql> select(-(-1.27));
+------------+
| (-(-1.27)) |
+------------+
| 1.27       |
+------------+
1 rows in set (0.07 sec)


Many thanks,

Adam


--
This list is a free service of LassoSoft: http://www.LassoSoft.com/
Search the list archives: http://www.ListSearch.com/Lasso/Browse/
Manage your subscription: http://www.ListSearch.com/Lasso/



Re: negative decimal issues

by Steve Piercy :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

On 11/5/09 at 6:53 PM, lists@... (Adam de Zoete) pronounced:

>       self -> 'newdecimal' = -(self -> 'input');

Is that getting interpreted as a string?  Try:

        self -> 'newdecimal' = -(decimal(self -> 'input'));

--steve

-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
Steve Piercy               Web Site Builder               Soquel, CA
<web@...>                  <http://www.StevePiercy.com/>


--
This list is a free service of LassoSoft: http://www.LassoSoft.com/
Search the list archives: http://www.ListSearch.com/Lasso/Browse/
Manage your subscription: http://www.ListSearch.com/Lasso/



Re: negative decimal issues

by Adam de Zoete-2 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Steve Piercy - Web Site Builder wrote:
> On 11/5/09 at 6:53 PM, lists@... (Adam de Zoete) pronounced:
>
>>       self -> 'newdecimal' = -(self -> 'input');
>
> Is that getting interpreted as a string?  Try:
>
>         self -> 'newdecimal' = -(decimal(self -> 'input'));

You're right, that does the trick. It's a little strange to have to cast
a decimal as a decimal in order to get it working.

I rewrote part of a ctype where it originally existed as...

self -> 'newdecimal' = -#input;

...which worked fine.

Adam



--
This list is a free service of LassoSoft: http://www.LassoSoft.com/
Search the list archives: http://www.ListSearch.com/Lasso/Browse/
Manage your subscription: http://www.ListSearch.com/Lasso/



Re: negative decimal issues

by Göran Törnquist-2 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Or, as in this specific situation:

self->'newdecimal' -= self->'input';

Note. There are a _lot_ of extraneous parenthesis in the previous
examples. The only reason for a parenthesis in the previous examples is
to handle the lack of a unary subraction operator.

/Göran

Adam de Zoete wrote:

> Douglas Burchard wrote:
>> On Nov 5, 2009, at 10:53 AM, Adam de Zoete wrote:
>>
>>> I'm having a bit of decimal math issues. A far as i'm aware setting
>>> a negative decimal negative should give me a positive decimal.
>>>
>>> I've produced a type below to demonstrate the issue.
>>
>> ...snip...
>>
>>>         self -> 'newdecimal' = -(self -> 'input');
>>
>> Why don't you try writing this as:
>>
>>         (self -> 'newdecimal') = ((self -> 'input') * (-1));
>
> Yes, that's the better method. I was assuming that Lasso would
> understand the negative assignment as other applications do.
>
> MacBook-Pro:~ adam$ echo "-(-1.27)" | bc
> 1.27
>
> mysql> select(-(-1.27));
> +------------+
> | (-(-1.27)) |
> +------------+
> | 1.27       |
> +------------+
> 1 rows in set (0.07 sec)
>
>
> Many thanks,
>
> Adam
>
>
> --
> This list is a free service of LassoSoft: http://www.LassoSoft.com/
> Search the list archives: http://www.ListSearch.com/Lasso/Browse/
> Manage your subscription: http://www.ListSearch.com/Lasso/
>
>
>


--
This message has been scanned for viruses and
dangerous content by MailScanner, and is
believed to be clean.


--
This list is a free service of LassoSoft: http://www.LassoSoft.com/
Search the list archives: http://www.ListSearch.com/Lasso/Browse/
Manage your subscription: http://www.ListSearch.com/Lasso/



Re: negative decimal issues

by Adam de Zoete-2 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Thanks for clarifying that Goran, in the situation i'm using this
Lasso's subtraction assignment (-=) won't do the trick, but it's useful
to know that a unary subtraction operator is missing.

Many thanks,

Adam


Göran Törnquist wrote:
> Or, as in this specific situation:
>
> self->'newdecimal' -= self->'input';
>
> Note. There are a _lot_ of extraneous parenthesis in the previous
> examples. The only reason for a parenthesis in the previous examples is
> to handle the lack of a unary subraction operator.
>
> /Göran

--
This list is a free service of LassoSoft: http://www.LassoSoft.com/
Search the list archives: http://www.ListSearch.com/Lasso/Browse/
Manage your subscription: http://www.ListSearch.com/Lasso/



Re: negative decimal issues

by Göran Törnquist-2 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Actually, I'm misinforming you. The unary subtraction operator is there,
but it needs parenthesis sometimes to distinguish it from tag params.

Here's some examples that might bring some light to the issue.

This works:
[
var('myVar' = 10);

-#myVar;
]

This doesn't:
[
var('myVar' = 10);

-integer(#myVar);
]

Again, this does:
[
var('myVar' = 10);

-(integer(#myVar));
]

/Göran

Adam de Zoete wrote:

> Thanks for clarifying that Goran, in the situation i'm using this
> Lasso's subtraction assignment (-=) won't do the trick, but it's
> useful to know that a unary subtraction operator is missing.
>
> Many thanks,
>
> Adam
>
>
> Göran Törnquist wrote:
>> Or, as in this specific situation:
>>
>> self->'newdecimal' -= self->'input';
>>
>> Note. There are a _lot_ of extraneous parenthesis in the previous
>> examples. The only reason for a parenthesis in the previous examples
>> is to handle the lack of a unary subraction operator.
>>
>> /Göran
>
> --
> This list is a free service of LassoSoft: http://www.LassoSoft.com/
> Search the list archives: http://www.ListSearch.com/Lasso/Browse/
> Manage your subscription: http://www.ListSearch.com/Lasso/
>
>
>


--
This message has been scanned for viruses and
dangerous content by MailScanner, and is
believed to be clean.


--
This list is a free service of LassoSoft: http://www.LassoSoft.com/
Search the list archives: http://www.ListSearch.com/Lasso/Browse/
Manage your subscription: http://www.ListSearch.com/Lasso/



Re: negative decimal issues

by Adam de Zoete-2 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Yes, in most cases it works if you recast the type, otherwise you'll get
the wrong value. It's just rather too easy to trip up over, hopefully
LP9 will offer better support.


local('localV' = decimal(-10.00));

decimal(-(#localV)); // Wrong

var('varV' = decimal(-10.00));

decimal(-($varV)); // Wrong

define_tag('reqneg');
        local('input') = decimal(-10.00);
        return(#input);
/define_tag;

decimal(-(reqneg)); // Wrong

define_type('reqnegtype');
        local('input') = decimal(-10.00);
       
        define_tag('eval');
                return(-(self -> 'input'));
        /define_tag;
/define_type;

decimal(reqnegtype -> eval); // Wrong



Göran Törnquist wrote:

> Actually, I'm misinforming you. The unary subtraction operator is there,
> but it needs parenthesis sometimes to distinguish it from tag params.
>
> Here's some examples that might bring some light to the issue.
>
> This works:
> [
> var('myVar' = 10);
>
> -#myVar;
> ]
>
> This doesn't:
> [
> var('myVar' = 10);
>
> -integer(#myVar);
> ]
>
> Again, this does:
> [
> var('myVar' = 10);
>
> -(integer(#myVar));
> ]
>
> /Göran
>
> Adam de Zoete wrote:
>> Thanks for clarifying that Goran, in the situation i'm using this
>> Lasso's subtraction assignment (-=) won't do the trick, but it's
>> useful to know that a unary subtraction operator is missing.
>>
>> Many thanks,
>>
>> Adam
>>
>>
>> Göran Törnquist wrote:
>>> Or, as in this specific situation:
>>>
>>> self->'newdecimal' -= self->'input';
>>>
>>> Note. There are a _lot_ of extraneous parenthesis in the previous
>>> examples. The only reason for a parenthesis in the previous examples
>>> is to handle the lack of a unary subraction operator.
>>>
>>> /Göran
>>
>> --
>> This list is a free service of LassoSoft: http://www.LassoSoft.com/
>> Search the list archives: http://www.ListSearch.com/Lasso/Browse/
>> Manage your subscription: http://www.ListSearch.com/Lasso/
>>
>>
>>
>
>

--
This list is a free service of LassoSoft: http://www.LassoSoft.com/
Search the list archives: http://www.ListSearch.com/Lasso/Browse/
Manage your subscription: http://www.ListSearch.com/Lasso/



Re: negative decimal issues

by Göran Törnquist-2 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

try adding a space to your examples, and quite a few of them will be
working.

/Göran

Adam de Zoete wrote:

> Yes, in most cases it works if you recast the type, otherwise you'll
> get the wrong value. It's just rather too easy to trip up over,
> hopefully LP9 will offer better support.
>
>
> local('localV' = decimal(-10.00));
>
> decimal(-(#localV));    //    Wrong
>
> var('varV' = decimal(-10.00));
>
> decimal(-($varV));    //    Wrong
>
> define_tag('reqneg');
>     local('input') = decimal(-10.00);
>     return(#input);
> /define_tag;
>
> decimal(-(reqneg));    //    Wrong
>
> define_type('reqnegtype');
>     local('input') = decimal(-10.00);
>    
>     define_tag('eval');
>         return(-(self -> 'input'));
>     /define_tag;
> /define_type;
>
> decimal(reqnegtype -> eval);    //    Wrong
>
>
>
> Göran Törnquist wrote:
>> Actually, I'm misinforming you. The unary subtraction operator is
>> there, but it needs parenthesis sometimes to distinguish it from tag
>> params.
>>
>> Here's some examples that might bring some light to the issue.
>>
>> This works:
>> [
>> var('myVar' = 10);
>>
>> -#myVar;
>> ]
>>
>> This doesn't:
>> [
>> var('myVar' = 10);
>>
>> -integer(#myVar);
>> ]
>>
>> Again, this does:
>> [
>> var('myVar' = 10);
>>
>> -(integer(#myVar));
>> ]
>>
>> /Göran
>>
>> Adam de Zoete wrote:
>>> Thanks for clarifying that Goran, in the situation i'm using this
>>> Lasso's subtraction assignment (-=) won't do the trick, but it's
>>> useful to know that a unary subtraction operator is missing.
>>>
>>> Many thanks,
>>>
>>> Adam
>>>
>>>
>>> Göran Törnquist wrote:
>>>> Or, as in this specific situation:
>>>>
>>>> self->'newdecimal' -= self->'input';
>>>>
>>>> Note. There are a _lot_ of extraneous parenthesis in the previous
>>>> examples. The only reason for a parenthesis in the previous
>>>> examples is to handle the lack of a unary subraction operator.
>>>>
>>>> /Göran
>>>
>>> --
>>> This list is a free service of LassoSoft: http://www.LassoSoft.com/
>>> Search the list archives: http://www.ListSearch.com/Lasso/Browse/
>>> Manage your subscription: http://www.ListSearch.com/Lasso/
>>>
>>>
>>>
>>
>>
>
> --
> This list is a free service of LassoSoft: http://www.LassoSoft.com/
> Search the list archives: http://www.ListSearch.com/Lasso/Browse/
> Manage your subscription: http://www.ListSearch.com/Lasso/
>
>
>


--
This message has been scanned for viruses and
dangerous content by MailScanner, and is
believed to be clean.


--
This list is a free service of LassoSoft: http://www.LassoSoft.com/
Search the list archives: http://www.ListSearch.com/Lasso/Browse/
Manage your subscription: http://www.ListSearch.com/Lasso/



Re: negative decimal issues

by Göran Törnquist-2 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Duh, cryptic suggestions never work out. Especially untested ones.

Forget about my last posting. This is what is correct.

No unary subtraction operator in Lasso 8.5.

I'll stop changing my mind now. :-)

/Göran

Göran Törnquist wrote:

> try adding a space to your examples, and quite a few of them will be
> working.
>
> /Göran
>
> Adam de Zoete wrote:
>> Yes, in most cases it works if you recast the type, otherwise you'll
>> get the wrong value. It's just rather too easy to trip up over,
>> hopefully LP9 will offer better support.
>>
>>
>> local('localV' = decimal(-10.00));
>>
>> decimal(-(#localV));    //    Wrong
>>
>> var('varV' = decimal(-10.00));
>>
>> decimal(-($varV));    //    Wrong
>>
>> define_tag('reqneg');
>>     local('input') = decimal(-10.00);
>>     return(#input);
>> /define_tag;
>>
>> decimal(-(reqneg));    //    Wrong
>>
>> define_type('reqnegtype');
>>     local('input') = decimal(-10.00);
>>         define_tag('eval');
>>         return(-(self -> 'input'));
>>     /define_tag;
>> /define_type;
>>
>> decimal(reqnegtype -> eval);    //    Wrong
>>
>>
>>
>> Göran Törnquist wrote:
>>> Actually, I'm misinforming you. The unary subtraction operator is
>>> there, but it needs parenthesis sometimes to distinguish it from tag
>>> params.
>>>
>>> Here's some examples that might bring some light to the issue.
>>>
>>> This works:
>>> [
>>> var('myVar' = 10);
>>>
>>> -#myVar;
>>> ]
>>>
>>> This doesn't:
>>> [
>>> var('myVar' = 10);
>>>
>>> -integer(#myVar);
>>> ]
>>>
>>> Again, this does:
>>> [
>>> var('myVar' = 10);
>>>
>>> -(integer(#myVar));
>>> ]
>>>
>>> /Göran
>>>
>>> Adam de Zoete wrote:
>>>> Thanks for clarifying that Goran, in the situation i'm using this
>>>> Lasso's subtraction assignment (-=) won't do the trick, but it's
>>>> useful to know that a unary subtraction operator is missing.
>>>>
>>>> Many thanks,
>>>>
>>>> Adam
>>>>
>>>>
>>>> Göran Törnquist wrote:
>>>>> Or, as in this specific situation:
>>>>>
>>>>> self->'newdecimal' -= self->'input';
>>>>>
>>>>> Note. There are a _lot_ of extraneous parenthesis in the previous
>>>>> examples. The only reason for a parenthesis in the previous
>>>>> examples is to handle the lack of a unary subraction operator.
>>>>>
>>>>> /Göran
>>>>
>>>> --
>>>> This list is a free service of LassoSoft: http://www.LassoSoft.com/
>>>> Search the list archives: http://www.ListSearch.com/Lasso/Browse/
>>>> Manage your subscription: http://www.ListSearch.com/Lasso/
>>>>
>>>>
>>>>
>>>
>>>
>>
>> --
>> This list is a free service of LassoSoft: http://www.LassoSoft.com/
>> Search the list archives: http://www.ListSearch.com/Lasso/Browse/
>> Manage your subscription: http://www.ListSearch.com/Lasso/
>>
>>
>>
>
>


--
This message has been scanned for viruses and
dangerous content by MailScanner, and is
believed to be clean.


--
This list is a free service of LassoSoft: http://www.LassoSoft.com/
Search the list archives: http://www.ListSearch.com/Lasso/Browse/
Manage your subscription: http://www.ListSearch.com/Lasso/



Re: negative decimal issues

by Adam de Zoete-2 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Yes totally cryptic, couldn't figure how a space would make the difference!


Göran Törnquist wrote:
> Duh, cryptic suggestions never work out. Especially untested ones.
>
> Forget about my last posting. This is what is correct.
>
> No unary subtraction operator in Lasso 8.5.
>
> I'll stop changing my mind now. :-)
>
> /Göran


--
This list is a free service of LassoSoft: http://www.LassoSoft.com/
Search the list archives: http://www.ListSearch.com/Lasso/Browse/
Manage your subscription: http://www.ListSearch.com/Lasso/