Mathematics Functions

上一篇 / 下一篇  2012-06-05 11:45:02 / 个人分类:性能测试

Mathematics functions allow you to perform. mathematical operations. Expand the category to view a list of the available functions.

 

Function Name

Description

floor

Gets the largest integral value that is less than x.

rand

Gets a random integer between 0 and RAND_MAX.

sqrt

Computes the square root of x.

srand

Seeds the pseudo-random number generator.

 

 

  例子:

  double sqrt(double x); //开平方根需要事先声明

   lr_output_message ("Square root of 9 = %f\n", sqrt(9));

   lr_output_message ("Square root of 8 = %f\n", sqrt(8));

   lr_output_message ("Square root of -8 = %f\n", sqrt(-8));

 

    例子:

   //调用rand之前先调用srand

   srand(time(NULL));

   //返回数值范围是0-RAND_MAX伪随机整数

   lr_output_message ("A number between (0,100): %d\n", rand() % 100);

   lr_output_message ("A number between (20,30): %d\n", rand() % 10+20);

   //调用rand之前先调用srand

        //返回数值范围是0-RAND_MAX伪随机整数

   srand(time(NULL));

   //返回数值范围是0-RAND_MAX伪随机整数0100

   lr_output_message

       ("A number between (0,100): %d\n", rand() % 100);

 

  例子:

   double floor(double x); //显示声明

        //整数部分取整,小数部分为零

   lr_output_message ("floor of 2.3 is %.1lf\n", floor(2.3));

   lr_output_message ("floor of 3.8 is %.1lf\n", floor(3.8));

        //负数往小取负整数

   lr_output_message ("floor of -2.3 is %.1lf\n", floor(-2.3));

   lr_output_message ("floor of -3.8 is %.1lf\n", floor(-3.8));

 

 

 

 


TAG:

 

评分:0

我来说两句

Open Toolbar