round
- Posted by =?iso-8859-2?B?qWtvZGE=?= <tone.skoda at SIOL.NET> Jun 05, 2000
- 514 views
------=_NextPart_000_0007_01BFCF0D.DFA63740 charset="iso-8859-2" Content-Transfer-Encoding: quoted-printable Could someone give me better round function, that rounds number. 1.4 to 1, 1.6 to 2. -1.7 to -2 etc I have written this one, but can't remeber how to do it better, = simpler. --if positive or negative --returns 1 or -1 global function NumberSign(atom num) if num<0 then return -1 else return 1 end if end function --/topic Utilities --/func abs( a ) --/desc Absolute value. --/ret Absolute value of the atom. global function abs( atom a ) if a < 0 then return -a else return a end if end function --rounds number global function round(atom a) atom fl fl=3Dfloor(a) if abs(a-fl)<0.5 then return fl else return floor(a+NumberSign(a)) end if end function ------=_NextPart_000_0007_01BFCF0D.DFA63740 charset="iso-8859-2" Content-Transfer-Encoding: quoted-printable <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"> <HTML><HEAD> <META content=3D"text/html; charset=3Diso-8859-2" = http-equiv=3DContent-Type> <META content=3D"MSHTML 5.00.2614.3401" name=3DGENERATOR> <STYLE></STYLE> </HEAD> <BODY bgColor=3D#ffffff> <DIV><FONT face=3DArial size=3D2>Could someone give me better round = function, that=20 rounds number.</FONT></DIV> <DIV><FONT face=3DArial size=3D2>1.4 to 1, 1.6 to 2.</FONT></DIV> <DIV><FONT face=3DArial size=3D2>-1.7 to -2 etc</FONT></DIV> <DIV> </DIV> <DIV><FONT face=3DArial size=3D2>I have written this one, but = can't remeber=20 how to do it better, simpler.</FONT></DIV> <DIV> </DIV> <DIV> </DIV> <DIV><FONT face=3DArial size=3D2>--if positive or negative<BR>--returns = 1 or=20 -1<BR>global function NumberSign(atom num)<BR> if num<0 then = return=20 -1<BR> else return 1 end if<BR>end function</FONT></DIV> <DIV> </DIV> <DIV><FONT face=3DArial size=3D2>--/topic Utilities<BR>--/func abs( a = )<BR>--/desc=20 Absolute value.<BR>--/ret Absolute value of the atom.</FONT></DIV> <DIV> </DIV> <DIV><FONT face=3DArial size=3D2>global function abs( atom a = )<BR> =20 if a < 0 then<BR> return=20 -a<BR> = return a<BR> end if<BR>end function</FONT></DIV> <DIV> </DIV> <DIV><FONT face=3DArial size=3D2><BR>--rounds number<BR>global function = round(atom=20 a)<BR> atom fl</FONT></DIV> <DIV> </DIV> <DIV><FONT face=3DArial size=3D2> fl=3Dfloor(a)<BR> if = abs(a-fl)<0.5 then=20 return fl<BR> else return floor(a+NumberSign(a))<BR> end = if<BR>end=20 ------=_NextPart_000_0007_01BFCF0D.DFA63740--