Welcome to mirror list, hosted at ThFree Co, Russian Federation.

s_floor.c « mathfp « libm « newlib - cygwin.com/git/newlib-cygwin.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 0dbc207f3fc2adc5d835d30184b5126fbf204fb1 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92

/* @(#)z_floor.c 1.0 98/08/13 */

/*
FUNCTION
<<floor>>, <<floorf>>, <<ceil>>, <<ceilf>>---floor and ceiling
INDEX
        floor
INDEX
        floorf
INDEX
        ceil
INDEX
        ceilf

ANSI_SYNOPSIS
        #include <math.h>
        double floor(double <[x]>);
        float floorf(float <[x]>);
        double ceil(double <[x]>);
        float ceilf(float <[x]>);

TRAD_SYNOPSIS
        #include <math.h>
        double floor(<[x]>)
        double <[x]>;
        float floorf(<[x]>)
        float <[x]>;
        double ceil(<[x]>)
        double <[x]>;
        float ceilf(<[x]>)
        float <[x]>;

DESCRIPTION
<<floor>> and <<floorf>> find
@tex
$\lfloor x \rfloor$,
@end tex
the nearest integer less than or equal to <[x]>.
<<ceil>> and <<ceilf>> find
@tex
$\lceil x\rceil$,
@end tex
the nearest integer greater than or equal to <[x]>.

RETURNS
<<floor>> and <<ceil>> return the integer result as a double.
<<floorf>> and <<ceilf>> return the integer result as a float.

PORTABILITY
<<floor>> and <<ceil>> are ANSI.
<<floorf>> and <<ceilf>> are extensions.

*/

/*****************************************************************
 * floor 
 *
 * Input:
 *   x  - floating point value
 *
 * Output:
 *   Smallest integer less than x.
 *
 * Description:
 *   This routine returns the smallest integer less than x.
 *
 *****************************************************************/

#include "fdlibm.h"
#include "zmath.h"

#ifndef _DOUBLE_IS_32BITS

double 
_DEFUN (floor, (double),
              double x)
{
  double f, y;

  if (x > -1.0 && x < 1.0)
    return (x >= 0 ? 0 : -1.0);

  y = modf (x, &f);

  if (y == 0.0)
    return (x);

  return (x >= 0 ? f : f - 1.0);
}

#endif /* _DOUBLE_IS_32BITS */