Note: This website is archived. For up-to-date information about D projects and development, please visit wiki.dlang.org.

Changeset 1553

Show
Ignore:
Timestamp:
05/25/10 04:03:09 (15 years ago)
Author:
walter
Message:

add @safe to builtin functions

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/phobos/std/math.d

    r1513 r1553  
    307307 * 
    308308 *      $(TABLE_SV 
    309309 *      $(TR $(TH x)                 $(TH cos(x)) $(TH invalid?)) 
    310310 *      $(TR $(TD $(NAN))            $(TD $(NAN)) $(TD yes)     ) 
    311311 *      $(TR $(TD $(PLUSMN)$(INFIN)) $(TD $(NAN)) $(TD yes)     ) 
    312312 *      ) 
    313313 * Bugs: 
    314314 *      Results are undefined if |x| >= $(POWER 2,64). 
    315315 */ 
    316316 
    317 pure nothrow real cos(real x);       /* intrinsic */ 
     317@safe pure nothrow real cos(real x);       /* intrinsic */ 
    318318 
    319319/*********************************** 
    320320 * Returns sine of x. x is in radians. 
    321321 * 
    322322 *      $(TABLE_SV 
    323323 *      $(TR $(TH x)               $(TH sin(x))      $(TH invalid?)) 
    324324 *      $(TR $(TD $(NAN))          $(TD $(NAN))      $(TD yes)) 
    325325 *      $(TR $(TD $(PLUSMN)0.0)    $(TD $(PLUSMN)0.0) $(TD no)) 
    326326 *      $(TR $(TD $(PLUSMNINF))    $(TD $(NAN))      $(TD yes)) 
    327327 *      ) 
    328328 * Bugs: 
    329329 *      Results are undefined if |x| >= $(POWER 2,64). 
    330330 */ 
    331331 
    332 pure nothrow real sin(real x);       /* intrinsic */ 
     332@safe pure nothrow real sin(real x);       /* intrinsic */ 
    333333 
    334334 
    335335/*********************************** 
    336336 *  sine, complex and imaginary 
    337337 * 
    338338 *  sin(z) = sin(z.re)*cosh(z.im) + cos(z.re)*sinh(z.im)i 
    339339 * 
    340340 * If both sin($(THETA)) and cos($(THETA)) are required, 
    341341 * it is most efficient to use expi($(THETA)). 
    342342 */ 
     
    387387 * Returns tangent of x. x is in radians. 
    388388 * 
    389389 *      $(TABLE_SV 
    390390 *      $(TR $(TH x)             $(TH tan(x))       $(TH invalid?)) 
    391391 *      $(TR $(TD $(NAN))        $(TD $(NAN))       $(TD yes)) 
    392392 *      $(TR $(TD $(PLUSMN)0.0)  $(TD $(PLUSMN)0.0) $(TD no)) 
    393393 *      $(TR $(TD $(PLUSMNINF))  $(TD $(NAN))       $(TD yes)) 
    394394 *      ) 
    395395 */ 
    396396 
    397 pure nothrow real tan(real x) 
     397@trusted pure nothrow real tan(real x) 
    398398{ 
    399399    version(Naked_D_InlineAsm_X86) { 
    400400    asm 
    401401    { 
    402402        fld     x[EBP]                  ; // load theta 
    403403        fxam                            ; // test for oddball values 
    404404        fstsw   AX                      ; 
    405405        sahf                            ; 
    406406        jc      trigerr                 ; // x is NAN, infinity, or empty 
    407407                                          // 387's can handle denormals 
     
    798798    assert(isNaN(atanh(real.nan))); 
    799799    assert(isNaN(atanh(-real.infinity))); 
    800800} 
    801801 
    802802/***************************************** 
    803803 * Returns x rounded to a long value using the current rounding mode. 
    804804 * If the integer value of x is 
    805805 * greater than long.max, the result is 
    806806 * indeterminate. 
    807807 */ 
    808 pure nothrow long rndtol(real x);    /* intrinsic */ 
     808@safe pure nothrow long rndtol(real x);    /* intrinsic */ 
    809809 
    810810 
    811811/***************************************** 
    812812 * Returns x rounded to a long value using the FE_TONEAREST rounding mode. 
    813813 * If the integer value of x is 
    814814 * greater than long.max, the result is 
    815815 * indeterminate. 
    816816 */ 
    817817extern (C) real rndtonl(real x); 
    818818 
     
    820820 * Compute square root of x. 
    821821 * 
    822822 *      $(TABLE_SV 
    823823 *      $(TR $(TH x)         $(TH sqrt(x))   $(TH invalid?)) 
    824824 *      $(TR $(TD -0.0)      $(TD -0.0)      $(TD no)) 
    825825 *      $(TR $(TD $(LT)0.0)  $(TD $(NAN))    $(TD yes)) 
    826826 *      $(TR $(TD +$(INFIN)) $(TD +$(INFIN)) $(TD no)) 
    827827 *      ) 
    828828 */ 
    829829 
    830 pure nothrow 
     830@safe pure nothrow 
    831831{ 
    832832    float sqrt(float x);    /* intrinsic */ 
    833833    double sqrt(double x);  /* intrinsic */ /// ditto 
    834834    real sqrt(real x);      /* intrinsic */ /// ditto 
    835835} 
    836836 
    837837pure nothrow creal sqrt(creal z) 
    838838{ 
    839839    creal c; 
    840840    real x,y,w,r; 
     
    13781378 
    13791379alias core.stdc.math.FP_ILOGB0   FP_ILOGB0; 
    13801380alias core.stdc.math.FP_ILOGBNAN FP_ILOGBNAN; 
    13811381 
    13821382 
    13831383/******************************************* 
    13841384 * Compute n * 2$(SUP exp) 
    13851385 * References: frexp 
    13861386 */ 
    13871387 
    1388 pure nothrow real ldexp(real n, int exp);    /* intrinsic */ 
     1388@safe pure nothrow real ldexp(real n, int exp);    /* intrinsic */ 
    13891389 
    13901390unittest { 
    13911391    assert(ldexp(1, -16384) == 0x1p-16384L); 
    13921392    assert(ldexp(1, -16382) == 0x1p-16382L); 
    13931393    int x; 
    13941394    real n = frexp(0x1p-16384L, x); 
    13951395    assert(n==0.5L); 
    13961396    assert(x==-16383); 
    13971397    assert(ldexp(n, x)==0x1p-16384L); 
    13981398     
     
    15721572 
    15731573/******************************* 
    15741574 * Returns |x| 
    15751575 * 
    15761576 *      $(TABLE_SV 
    15771577 *      $(TR $(TH x)                 $(TH fabs(x))) 
    15781578 *      $(TR $(TD $(PLUSMN)0.0)      $(TD +0.0) ) 
    15791579 *      $(TR $(TD $(PLUSMN)$(INFIN)) $(TD +$(INFIN)) ) 
    15801580 *      ) 
    15811581 */ 
    1582 pure nothrow real fabs(real x);      /* intrinsic */ 
     1582@safe pure nothrow real fabs(real x);      /* intrinsic */ 
    15831583 
    15841584 
    15851585/*********************************************************************** 
    15861586 * Calculates the length of the 
    15871587 * hypotenuse of a right-angled triangle with sides of length x and y. 
    15881588 * The hypotenuse is the value of the square root of 
    15891589 * the sums of the squares of x and y: 
    15901590 * 
    15911591 *      sqrt($(POW x, 2) + $(POW y, 2)) 
    15921592 * 
     
    17711771real nearbyint(real x) { return core.stdc.math.nearbyintl(x); } 
    17721772 
    17731773/********************************** 
    17741774 * Rounds x to the nearest integer value, using the current rounding 
    17751775 * mode. 
    17761776 * If the return value is not equal to x, the FE_INEXACT 
    17771777 * exception is raised. 
    17781778 * $(B nearbyint) performs 
    17791779 * the same operation, but does not set the FE_INEXACT exception. 
    17801780 */ 
    1781 pure nothrow real rint(real x);      /* intrinsic */ 
     1781@safe pure nothrow real rint(real x);      /* intrinsic */ 
    17821782 
    17831783/*************************************** 
    17841784 * Rounds x to the nearest integer value, using the current rounding 
    17851785 * mode. 
    17861786 * 
    17871787 * This is generally the fastest method to convert a floating-point number 
    17881788 * to an integer. Note that the results from this function 
    17891789 * depend on the rounding mode, if the fractional part of x is exactly 0.5. 
    17901790 * If using the default rounding mode (ties round to even integers) 
    17911791 * lrint(4.5) == 4, lrint(5.5)==6. 
     
    36283628alias isFinite isfinite; 
    36293629alias isNormal isnormal; 
    36303630alias isSubnormal issubnormal; 
    36313631alias isInfinity isinf; 
    36323632 
    36333633/* ********************************** 
    36343634 * Building block functions, they 
    36353635 * translate to a single x87 instruction. 
    36363636 */ 
    36373637 
    3638 pure nothrow real yl2x(real x, real y);         // y * log2(x) 
    3639 pure nothrow real yl2xp1(real x, real y);       // y * log2(x + 1) 
     3638@safe pure nothrow real yl2x(real x, real y);         // y * log2(x) 
     3639@safe pure nothrow real yl2xp1(real x, real y);       // y * log2(x + 1) 
    36403640 
    36413641unittest 
    36423642{ 
    36433643    version (INLINE_YL2X) 
    36443644    { 
    36453645        assert(yl2x(1024, 1) == 10); 
    36463646        assert(yl2xp1(1023, 1) == 10); 
    36473647    } 
    36483648}