C language Fmod () function: modulus of floating-point numbers (redundancy)

Source: Internet
Author: User
Tags modulus

Header files: #include <math.h>

Fmod () is used to model the floating-point number (redundancy), the prototype is:
Double Fmod (double x);

Set the return value to RET, then x = n * y + ret, where n is an integer, ret and x have the same symbol, and the absolute value of RET is less than the absolute number of Y. If x = 0, then ret = NaN.

The Fmod function calculates the F floating-point remainder of x divided by y so that x = I*y + F, where I is an integer, F and x have the same symbol, and the absolute value of f is less than the absolute number of Y.

The Fmod () function can perform modulo operations on floating-point data, and the latter number can be 0, when the function returns Nan.

The sign of the computed result is the same as the former (x), if the former is a smaller number and the latter is a larger number, then the result is a small number directly.

Cases:

Problem E: Billiards collision Time Limit:1 Sec Memory limit:128 MB
Submit:80 solved:18
[Submit] [Status] [Web Board] Description

In a planar Cartesian coordinate system, the billiard table is a rectangle in the lower left corner (0,0), upper right corner (L,W). There is a spherical sphere (x,y), and a round ball with a radius of R is placed on the billiard table (the whole ball is in the billiard table). After the impact, the ball along the polar angle of a ray (i.e.:x Positive half axis counterclockwise to this ray angle is a) fly out, each encounter the table with a full elastic collision (the rate of the ball is constant, the reflection angle is equal to the angle of incidence).

If the velocity of the ball is v, where is the sphere after thes time unit?

Input

The input file contains up to 25 sets of test data, one row per data, 8 positive integers L,W,x,y,R,a, v,s(100<=L,W<=105, 1<=R<=5, R<= x<=L-R, R<=y<=W-R, 0<= a<360, 1<=v,s<=105), meaning see topic description. L=W=x=y=R=a=v=s= 0 means that the input ends and your program should not handle this line.

Sample Input
100 100 80 10 5 90 2 23110 100 70 10 5 180 1 99990 0 0 0 0 0 0 0
Sample Output
80.00 56.0071.00 10.00

#include <stdio.h> #include <math.h>int main () {    double l,w,x,y,r,a,v,s;    while (scanf ("%lf%lf%lf%lf%lf%lf%lf%lf", &l,&w,&x,&y,&r,&a,&v,&s) ==8)    {        if (! L) break            ;        X=x-r;        Y=y-r;        l=l-r*2;        w=w-r*2;        A=a*acos (0.0)/90.0;        Double Dx=fmod (Fmod (V*s*cos (a), l*2) +l*2,l*2);        Double Dy=fmod (Fmod (V*s*sin (a), w*2) +w*2,w*2);        if (x+dx<=l)            x=x+dx;        else if (x+dx<=l*2)            x=l-(x+dx-l);        else            x=x+dx-l*2;        if (y+dy<=w)            y=y+dy;        else if (y+dy<=w*2)            y=w-(y+dy-w);        else            y=y+dy-w*2;        printf ("%.2lf%.2lf\n", x+r,y+r);    }    return 0;}

  

C language Fmod () function: modulus of floating-point numbers (redundancy)

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.