Difference between revisions of "ListToWholeNumbers"

From Second Life Wiki
Jump to navigation Jump to search
(New page: {{LSL Header}} __NOTOC__ <div id="box"> == Function: list ListToWholeNumbers(list {{LSL Param|mylist}}); == <div style="padding: 0.5em;"> Removes one item from a list. See also: [...)
 
m (<lsl> tag to <source>)
 
(5 intermediate revisions by 3 users not shown)
Line 1: Line 1:
{{LSL Header}} __NOTOC__
{{LSL_Function
<div id="box">
|mode=user
== Function: [[list]] ListToWholeNumbers([[list]] {{LSL Param|mylist}}); ==
|func=ListToWholeNumbers
<div style="padding: 0.5em;">
|p1_type=list|p1_name=mylist
Removes one item from a list.
|return_type=list
 
|return_text=that contains the elements of '''myList''' but with the float elements having their fractional parts removed.
|func_desc=Takes a list and truncates each float in the list so that it is a whole number.
|func_footnote=
See also: [[List|Lists]]
See also: [[List|Lists]]
 
|examples=
<lsl>
<source lang="lsl2">list myWholeNumberList = ListToWholeNumbers( [1.04, 10.789, 4.643] );//yields [1,10,4]</source>
list ListToWholeNumbers(list myList) {
|spec=<source lang="lsl2">list ListToWholeNumbers(list myList)
    list myConvertedList = [];
{
     integer ListLength = llGetListLength(myList);
     integer ListLength = llGetListLength(myList);
     integer f = 0;
     integer i = -1;
     while (f <= (ListLength - 1)) {
     while (++i < ListLength)
        string w =llList2Key(myList, f);
    {
        integer y = (integer)w;
        if(TYPE_FLOAT == llGetListEntryType(myList, i))
        myConvertedList = (myConvertedList=[]) + myConvertedList + y;
        {
        f=f+1;
            float f = llList2Float(myList, i);
            if(llFabs(f) < 0x1000000)//can it have an fpart?
                f = (integer)f;
            myList = (myList = []) + llListReplaceList(myList, (list)f, i, i);
         }
         }
     return myConvertedList;
    }
}
     return myList;
 
}</source>
</lsl>
|helpers
 
|also_functions
list myWholeNumberList = ListToWholeNumbers(1.04,10.789,4.643);
|also_events
//yields [1,10,4]
|also_tests
 
|also_articles
 
|location
</div>
|notes
 
|cat1=Examples
{{LSLC|Examples|ListToWholeNumbers}}
|cat2=User-Defined Functions
|cat3
|cat4
}}

Latest revision as of 15:22, 22 January 2015

Summary

Function: list ListToWholeNumbers( list mylist );

Takes a list and truncates each float in the list so that it is a whole number.
Returns a list that contains the elements of myList but with the float elements having their fractional parts removed.

• list mylist

See also: Lists

Specification

list ListToWholeNumbers(list myList)
{
    integer ListLength = llGetListLength(myList);
    integer i = -1;
    while (++i < ListLength)
    {
        if(TYPE_FLOAT == llGetListEntryType(myList, i))
        {
            float f = llList2Float(myList, i);
            if(llFabs(f) < 0x1000000)//can it have an fpart?
                f = (integer)f;
            myList = (myList = []) + llListReplaceList(myList, (list)f, i, i);
        }
    }
    return myList;
}

Examples

list myWholeNumberList = ListToWholeNumbers( [1.04, 10.789, 4.643] );//yields [1,10,4]