Difference between revisions of "ListToWholeNumbers"
Jump to navigation
Jump to search
m |
|||
Line 1: | Line 1: | ||
{{ | {{LSL_Function | ||
|mode=user | |||
== | |func=ListToWholeNumbers | ||
|p1_type=list|p1_name=mylist | |||
|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> | <lsl>list myWholeNumberList = ListToWholeNumbers( [1.04, 10.789, 4.643] );//yields [1,10,4]</lsl> | ||
list ListToWholeNumbers(list myList) { | |spec=<lsl>list ListToWholeNumbers(list myList) | ||
{ | |||
integer ListLength = llGetListLength(myList); | integer ListLength = llGetListLength(myList); | ||
integer | integer i = -1; | ||
while ( | 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 | } | ||
} | return myList; | ||
}</lsl> | |||
</lsl> | |helpers | ||
|also_functions | |||
|also_events | |||
|also_tests | |||
|also_articles | |||
|location | |||
|notes | |||
|cat1=Examples | |||
|cat2 | |||
|cat3 | |||
|cat4 | |||
}} |
Revision as of 20:05, 14 July 2008
LSL Portal | Functions | Events | Types | Operators | Constants | Flow Control | Script Library | Categorized Library | Tutorials |
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
<lsl>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;
}</lsl>
Examples
<lsl>list myWholeNumberList = ListToWholeNumbers( [1.04, 10.789, 4.643] );//yields [1,10,4]</lsl>