In case Flash no longer exists; a copy of this site is included in the Flashpoint archive's "ultimate" collection.

Dead Code Preservation :: Archived AS3 works from wonderfl.net

forked from: Faster ceil, round, floor

Get Adobe Flash player
by tohjg85 18 Jan 2011
/**
 * Copyright tohjg85 ( http://wonderfl.net/user/tohjg85 )
 * MIT License ( http://www.opensource.org/licenses/mit-license.php )
 * Downloaded from: http://wonderfl.net/c/xhPH
 */

// forked from jozefchutka's Faster ceil, round, floor
package
{
    import flash.display.Sprite;
    import flash.display.StageAlign;
    import flash.display.StageScaleMode;
    import flash.text.TextField;

    [SWF(width="465", height="465", frameRate="30", backgroundColor="#FFFFFF")]
    public class WonderflApp extends Sprite
    {
        public function WonderflApp():void
        {
            stage.scaleMode = StageScaleMode.NO_SCALE;
            stage.align = StageAlign.TOP_LEFT;
            
            var tf:TextField = new TextField();
            tf.width = stage.stageWidth;
            tf.height = stage.stageHeight;
            tf.text = "";
            tf.wordWrap = true;
            tf.multiline = true;
            addChild(tf);
            
            var n:Number, d:Date;
            var c:Number = 500000;
            
            tf.appendText("TESTS:");
            for(n=2;n>=-2;n-=.1)
                tf.appendText(Math.floor(n) == floor(n) ? "1 " : "0 ");
                
            for(n=2;n>=-2;n-=.1)
                tf.appendText(Math.round(n) == round(n) ? "1 " : "0 ");
                
            for(n=2;n>=-2;n-=.1)
                tf.appendText(Math.ceil(n) == ceil(n) ? "1 " : "0 ");
            tf.appendText("... FINISHED.\n");
            
            d=new Date;
            for(n=c;n>=-c;n-=.1) emptyf(n);
            var e:Number = new Date().time - d.time;
            
            
            d=new Date;
            for(n=c;n>=-c;n-=.1) mfloor(n);
            tf.appendText("Math.floor(): " + (new Date().time - d.time - e) + " ms\n");
            
            d=new Date;
            for(n=c;n>=-c;n-=.1) floor(n);
            tf.appendText("floor(): " + (new Date().time - d.time - e) + " ms\n");
            
            d=new Date;
            for(n=c;n>=-c;n-=.1) bfloor(n);
            tf.appendText("bfloor(): " + (new Date().time - d.time - e) + "ms\n");
                        
            d=new Date;
            for(n=c;n>=-c;n-=.1) mround(n);
            tf.appendText("Math.round(): " + (new Date().time - d.time - e) + " ms\n");
            
            d=new Date;
            for(n=c;n>=-c;n-=.1) round(n);
            tf.appendText("round(): " + (new Date().time - d.time - e) + " ms\n");
            
            d=new Date;
            for(n=c;n>=-c;n-=.1) bround(n);
            tf.appendText("bround(): "+ (new Date().time - d.time - e) + "ms\n");
            
            d=new Date;
            for(n=c;n>=-c;n-=.1) mceil(n);
            tf.appendText("Math.ceil(): " + (new Date().time - d.time - e) + " ms\n");
            
            d=new Date;
            for(n=c;n>=-c;n-=.1) ceil(n);
            tf.appendText("ceil(): " + (new Date().time - d.time - e) + " ms\n");
         }
         
         private function emptyf(n:Number):Number{return n;}
         private function mfloor(n:Number):Number{return Math.floor(n);}
         private function mround(n:Number):Number{return Math.round(n);}
         private function mceil(n:Number):Number{return Math.ceil(n);}
         
         
         private function floor(n:Number):int
         {
             var ni:int = n;
             return (n < 0 && n != ni) ? ni - 1 : ni;
         }
         
         private function round(n:Number):int
         {
             return n < -.5 ? n - .5 : n + .5;
         }
         
         private function ceil(n:Number):int
         {
             var ni:int = n;
             return (n >= 0 && n != ni) ? ni + 1 : ni;
         }
         
         private function bfloor(n:Number):int
         {
             return n | 0;
         }
         
         private function bround(n:Number):int
         {
             return (n+.5) | 0;
         }



    }
}