1. the rad function
- Posted by John Worthington <woodmage at EARTHLINK.NET> Sep 01, 1998
- 537 views
Roy Shepherd wrote: > John Worthinhton wrote > >> Roy Shepherd wrote: > >> Doug Cox wrote: Well, you get the idea. > >> function rad(atom sum) > >> sum = sum + (180/PI) > >> return sum > >> end function > >but ..... Shouldn't that be "sum = sum * 180 / PI" instead of +??? > I stand corrected. Apologises to all. Well spotted John. All I can say is "WHEW". ;') Also, seems like people are trying in the interest of speed to leave out steps, so going by that logic, would this be a hair better? (That sentence should be taken out and shot, I think, but hopefully, it managed to make sense anyway?) function rad2(atom sum) return sum*180/PI end function ___ _|ohn
2. Re: the rad function
- Posted by Jeffrey Fielding <JJProg at CYBERBURY.NET> Sep 01, 1998
- 553 views
- Last edited Sep 02, 1998
John wrote: >Roy Shepherd wrote: >> John Worthinhton wrote >> >> Roy Shepherd wrote: > > >> Doug Cox wrote: >Well, you get the idea. >> >> function rad(atom sum) >> >> sum =3D sum + (180/PI) > > >> return sum >> >> end function >> >but ..... Shouldn't that be "sum =3D sum * 180 / PI" instead of +??? >> I stand corrected. Apologises to all. Well spotted John. >All I can say is "WHEW". ;') >Also, seems like people are trying in the interest of speed to leave out steps, so >going by that logic, would this be a hair better? (That sentence should be taken >out and shot, I think, but hopefully, it managed to make sense anyway?) >function rad2(atom sum) >return sum*180/PI >end function >___ >_|ohn Well, if you want even more speed, you could use constant PI =3D 3.14159265359 constant PI_DIV_180 =3D 180 / PI function rad(atom s) s =3D s * PI_DIV_180 return s end function I wrote a simple testing program to test the following functions for rad: constant PI =3D 3.14159265359 constant A =3D 180 / PI function rad1(atom s) return s + (180 / PI) end function function rad2(atom s) return s * (180 / PI) end function function rad3(atom s) s =3D s + (180 / PI) return s end function function rad4(atom s) s =3D s * (180 / PI) return s end function function rad5(atom s) return s + A end function function rad6(atom s) return s * A end function function rad7(atom s) s =3D s + A return s end function function rad8(atom s) s =3D s * A return s end function sequence times, r atom tm, a r =3D {} times =3D {} for i =3D 1 to 8 do r =3D r & routine_id(sprintf("rad%d",i)) times =3D times & 0 end for -- You may want to change the maximim value for i or k because it runs kind of -- slowly. for i =3D 1 to 100 do for j =3D 1 to 8 do tm =3D time() for k =3D 1 to 1000 do a =3D call_func(r[j],{i}) end for tm =3D time() - tm if times[j] =3D 0 then times[j] =3D tm else times[j] =3D (times[j] + tm) / 2 end if end for end for for i =3D 1 to 8 do printf(1, "%f\n",{times[i]}) end for Jeffrey Fielding JJProg at cyberbury.net