Math problem

classic Classic list List threaded Threaded
9 messages Options
Reply | Threaded
Open this post in threaded view
|

Math problem

mpower
Hi everyone,
I've got a problem with the result of the variables bellow. Var left
and ten doesn't give me what I want. Left gives me 2 and ten gives me
24 when it should be 6 and 20. Does this has to do something with the
var/sting type? You can see the live result here:

http://www.rosling.eu/sidnr.lasso

Inline:
        -Database='forum',
        -Table='inlagg',
        -Username='xxx',
        -Password='xxx',
        -FindAll;

        Var:
            'found' = Found_Count,
            'length' = String_Length: $found,
            'left' = String_Extract: $found, -StartPosition=2, -EndPosition=2,
            'ten' = (Math_Sub: $found, $left);

/Inline;

--
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/

Reply | Threaded
Open this post in threaded view
|

Re: Math problem

Doug Gentry
Yep - at the very least you need to cast left as an integer. Right now  
it is a string.  Maybe something like

'left'=(integer(String_Extract: $found, -StartPosition=2, -
EndPosition=2)),

Now depending on what you're trying to do there is probably a more  
elegant mathematical model that can get you what you need.

...Doug


On Sep 16, 2008, at 11:08 PM, Jonas Rosling wrote:

> Hi everyone,
> I've got a problem with the result of the variables bellow. Var left
> and ten doesn't give me what I want. Left gives me 2 and ten gives me
> 24 when it should be 6 and 20. Does this has to do something with the
> var/sting type? You can see the live result here:
>
> http://www.rosling.eu/sidnr.lasso
>
> Inline:
>        -Database='forum',
>        -Table='inlagg',
>        -Username='xxx',
>        -Password='xxx',
>        -FindAll;
>
>        Var:
>            'found' = Found_Count,
>            'length' = String_Length: $found,
>            'left' = String_Extract: $found, -StartPosition=2, -
> EndPosition=2,
>            'ten' = (Math_Sub: $found, $left);
>
> /Inline;
>
> --
> 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/
>



---
Doug Gentry
Dynapolis & Southern Oregon University
p:  541-261-8501 / Toll Free: 866-890-6013
[hidden email]
www.dynapolis.com - blog: www.plain-sense.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/

Reply | Threaded
Open this post in threaded view
|

Re: Math problem

James Harvard
In reply to this post by mpower
Firstly I would recommend putting brackets around  tags with parameters to avoid any ambiguity.

'length' = (String_Length:$found),

Also, if you are using a variable in another variable's declaration put them in separate var tags. (This doesn't seem to be a problem when I test it now, but I *know* this has given me problems in the past.)

var: 'x' = 1, 'y' = (2 + $x) ; // bad

var: 'x' = 1 ;
var: 'y' = (2 + $x) ; // good

If you want to get the tens and digits from a number this is slightly simpler, I think:

var: 'found' = 26 ;
var: 'tens' = (math_floor: ($found/10.0) ) ;
var: 'digits' = ($found % 10) ;

'tens = ' + $tens ;
'<br />digits = ' + $digits ;

HTH,
James

>Hi everyone,
>I've got a problem with the result of the variables bellow. Var left
>and ten doesn't give me what I want. Left gives me 2 and ten gives me
>24 when it should be 6 and 20. Does this has to do something with the
>var/sting type? You can see the live result here:
>
>http://www.rosling.eu/sidnr.lasso
>
>Inline:
>        -Database='forum',
>        -Table='inlagg',
>        -Username='xxx',
>        -Password='xxx',
>        -FindAll;
>
>        Var:
>            'found' = Found_Count,
>            'length' = String_Length: $found,
>            'left' = String_Extract: $found, -StartPosition=2, -EndPosition=2,
>            'ten' = (Math_Sub: $found, $left);
>
>/Inline;

--
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/

Reply | Threaded
Open this post in threaded view
|

Re: Math problem

James Harvard
I don't know how large the numbers you're dealing with are, but just for kicks ...

define_tag: 'integer_parts', -required='n', -type='integer' ;
        local: 's' = (string:#n) ;
        #s->reverse;
        local: 'power' = 0, 'out' = array ;
        iterate: #s, local('i') ;
                #out->(insert: #i = ((math_pow:10,#power) + 's') );
                #power += 1 ;
        /iterate;
        #out->reverse;
        return: #out ;
/define_tag;

integer_parts: 1234 ;

:-)

James

--
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/

Reply | Threaded
Open this post in threaded view
|

Re: Math problem

Bil Corry-3
In reply to this post by mpower
Jonas Rosling wrote on 9/17/2008 1:08 AM:
>         Var:
>             'found' = Found_Count,
>             'length' = String_Length: $found,
>             'left' = String_Extract: $found, -StartPosition=2, -EndPosition=2,
>             'ten' = (Math_Sub: $found, $left);

Do this:

Var(
  'found'  = string(Found_Count),
  'length' = $found->size,
  'left'   = integer($found->get($length)),
  'ten'    = Found_Count - $left
);


- Bil


--
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/

Reply | Threaded
Open this post in threaded view
|

Re: Math problem

James Harvard
At 2:22 pm -0500 17/9/08, Bil Corry wrote:
>Do this:
>
>Var(
> 'found'  = string(Found_Count),
> 'length' = $found->size,
> 'left'   = integer($found->get($length)),
> 'ten'    = Found_Count - $left
>);

Am I going mad*, or was this ...

At 10:18 am +0100 17/9/08, James Harvard wrote:
>Also, if you are using a variable in another variable's declaration put them in separate var tags. (This doesn't seem to be a problem when I test it now, but I *know* this has given me problems in the past.)
>
>var: 'x' = 1, 'y' = (2 + $x) ; // bad
>
>var: 'x' = 1 ;
>var: 'y' = (2 + $x) ; // good

... an issue once?

James

* = Rhetorical question. Quiet at the back.

--
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/

Reply | Threaded
Open this post in threaded view
|

Re: Math problem

Trevor Borgmeier
James Harvard wrote:

> At 2:22 pm -0500 17/9/08, Bil Corry wrote:
>  
>> Do this:
>>
>> Var(
>> 'found'  = string(Found_Count),
>> 'length' = $found->size,
>> 'left'   = integer($found->get($length)),
>> 'ten'    = Found_Count - $left
>> );
>>    
>
> Am I going mad*, or was this ...
>
> At 10:18 am +0100 17/9/08, James Harvard wrote:
>  
>> Also, if you are using a variable in another variable's declaration put them in separate var tags. (This doesn't seem to be a problem when I test it now, but I *know* this has given me problems in the past.)
>>
>> var: 'x' = 1, 'y' = (2 + $x) ; // bad
>>
>> var: 'x' = 1 ;
>> var: 'y' = (2 + $x) ; // good
>>    
>
> ... an issue once?
>
> James
>
> * = Rhetorical question. Quiet at the back.
>
>  

Yes, I noticed this changed at some point as well.  It wasn't always
possible...

-Trevor

--
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/

Reply | Threaded
Open this post in threaded view
|

Re: Math problem

Bil Corry-3
In reply to this post by James Harvard
James Harvard wrote on 9/17/2008 3:06 PM:

> Am I going mad*, or was this ...
>
> At 10:18 am +0100 17/9/08, James Harvard wrote:
>> Also, if you are using a variable in another variable's declaration put them in separate var tags. (This doesn't seem to be a problem when I test it now, but I *know* this has given me problems in the past.)
>>
>> var: 'x' = 1, 'y' = (2 + $x) ; // bad
>>
>> var: 'x' = 1 ;
>> var: 'y' = (2 + $x) ; // good
>
> ... an issue once?

It was.  And I thought it still was until this thread.


- Bil


--
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/

Reply | Threaded
Open this post in threaded view
|

Re: Math problem

mpower
Thanks alot everyone! This help me alot and I learned to code a bit better.

// Jonas

--
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/