| From: Adam de Zoete | Date Sent: 2009-11-05 10:53:57 |
| Subject: negative decimal issues | To: Lasso Talk |
| Navigation: First Message | Previous Message | Next Message | Last 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
| From: Douglas Burchard | Date Sent: 2009-11-05 13:59:31 |
| Subject: Re: negative decimal issues | To: Lasso Talk |
| Navigation: First Message | Previous Message | Next Message | Last 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@[Protected]
http://www.douglasburchard.com/
| From: Adam de Zoete | Date Sent: 2009-11-05 14:53:42 |
| Subject: Re: negative decimal issues | To: Lasso Talk |
| Navigation: First Message | Previous Message | Next Message | Last 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
| From: Steve Piercy - Web Site Builder | Date Sent: 2009-11-05 14:55:40 |
| Subject: Re: negative decimal issues | To: Lasso Talk |
| Navigation: First Message | Previous Message | Next Message | Last Message | |
On 11/5/09 at 6:53 PM, lists@[Protected] (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@[Protected]> <http://www.StevePiercy.com/>
| From: Adam de Zoete | Date Sent: 2009-11-05 15:17:43 |
| Subject: Re: negative decimal issues | To: Lasso Talk |
| Navigation: First Message | Previous Message | Next Message | Last Message | |
Steve Piercy - Web Site Builder wrote:
> On 11/5/09 at 6:53 PM, lists@[Protected] (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
| From: Göran Törnquist | Date Sent: 2009-11-06 03:57:13 |
| Subject: Re: negative decimal issues | To: Lasso Talk |
| Navigation: First Message | Previous Message | Next Message | Last 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.
/Gran
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 message has been scanned for viruses and
dangerous content by MailScanner, and is
believed to be clean.
| From: Adam de Zoete | Date Sent: 2009-11-06 04:05:42 |
| Subject: Re: negative decimal issues | To: Lasso Talk |
| Navigation: First Message | Previous Message | Next Message | Last 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
Gran Trnquist 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.
>
> /Gran
| From: Göran Törnquist | Date Sent: 2009-11-06 06:30:44 |
| Subject: Re: negative decimal issues | To: Lasso Talk |
| Navigation: First Message | Previous Message | Next Message | Last 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));
]
/Gran
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
>
>
> Gran Trnquist 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.
>>
>> /Gran
>
> --
>
>
>
--
This message has been scanned for viruses and
dangerous content by MailScanner, and is
believed to be clean.
| From: Adam de Zoete | Date Sent: 2009-11-06 07:22:54 |
| Subject: Re: negative decimal issues | To: Lasso Talk |
| Navigation: First Message | Previous Message | Next Message | Last 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
Gran Trnquist 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));
> ]
>
> /Gran
>
> 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
>>
>>
>> Gran Trnquist 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.
>>>
>>> /Gran
| From: Göran Törnquist | Date Sent: 2009-11-06 09:34:07 |
| Subject: Re: negative decimal issues | To: Lasso Talk |
| Navigation: First Message | Previous Message | Next Message | Last Message | |
try adding a space to your examples, and quite a few of them will be
working.
/Gran
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
>
>
>
> Gran Trnquist 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));
>> ]
>>
>> /Gran
>>
>> 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
>>>
>>>
>>> Gran Trnquist 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.
>>>>
>>>> /Gran
>>>
>>> --
>>>
>>>
>>>
>>
>>
>
> --
>
>
>
--
This message has been scanned for viruses and
dangerous content by MailScanner, and is
believed to be clean.
| From: Göran Törnquist | Date Sent: 2009-11-06 09:53:31 |
| Subject: Re: negative decimal issues | To: Lasso Talk |
| Navigation: First Message | Previous Message | Next Message | Last 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. :-)
/Gran
Gran Trnquist wrote:
> try adding a space to your examples, and quite a few of them will be
> working.
>
> /Gran
>
> 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
>>
>>
>>
>> Gran Trnquist 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));
>>> ]
>>>
>>> /Gran
>>>
>>> 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
>>>>
>>>>
>>>> Gran Trnquist 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.
>>>>>
>>>>> /Gran
>>>>
>>>> --
>>>>
>>>>
>>>>
>>>
>>>
>>
>> --
>>
>>
>>
>
>
--
This message has been scanned for viruses and
dangerous content by MailScanner, and is
believed to be clean.
| From: Adam de Zoete | Date Sent: 2009-11-06 09:58:05 |
| Subject: Re: negative decimal issues | To: Lasso Talk |
| Navigation: First Message | Previous Message | Next Message | Last Message | |
Yes totally cryptic, couldn't figure how a space would make the difference!
Gran Trnquist 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. :-)
>
> /Gran