Last change
on this file since 503 was
444,
checked in by satin@…, 6 years ago
|
add newlib,libalmos-mkh, restructure shared_syscalls.h and mini-libc
|
File size:
1.4 KB
|
Line | |
---|
1 | |
---|
2 | /* @(#)z_floor.c 1.0 98/08/13 */ |
---|
3 | |
---|
4 | /* |
---|
5 | FUNCTION |
---|
6 | <<floor>>, <<floorf>>, <<ceil>>, <<ceilf>>---floor and ceiling |
---|
7 | INDEX |
---|
8 | floor |
---|
9 | INDEX |
---|
10 | floorf |
---|
11 | INDEX |
---|
12 | ceil |
---|
13 | INDEX |
---|
14 | ceilf |
---|
15 | |
---|
16 | SYNOPSIS |
---|
17 | #include <math.h> |
---|
18 | double floor(double <[x]>); |
---|
19 | float floorf(float <[x]>); |
---|
20 | double ceil(double <[x]>); |
---|
21 | float ceilf(float <[x]>); |
---|
22 | |
---|
23 | DESCRIPTION |
---|
24 | <<floor>> and <<floorf>> find |
---|
25 | @tex |
---|
26 | $\lfloor x \rfloor$, |
---|
27 | @end tex |
---|
28 | the nearest integer less than or equal to <[x]>. |
---|
29 | <<ceil>> and <<ceilf>> find |
---|
30 | @tex |
---|
31 | $\lceil x\rceil$, |
---|
32 | @end tex |
---|
33 | the nearest integer greater than or equal to <[x]>. |
---|
34 | |
---|
35 | RETURNS |
---|
36 | <<floor>> and <<ceil>> return the integer result as a double. |
---|
37 | <<floorf>> and <<ceilf>> return the integer result as a float. |
---|
38 | |
---|
39 | PORTABILITY |
---|
40 | <<floor>> and <<ceil>> are ANSI. |
---|
41 | <<floorf>> and <<ceilf>> are extensions. |
---|
42 | |
---|
43 | */ |
---|
44 | |
---|
45 | /***************************************************************** |
---|
46 | * floor |
---|
47 | * |
---|
48 | * Input: |
---|
49 | * x - floating point value |
---|
50 | * |
---|
51 | * Output: |
---|
52 | * Smallest integer less than x. |
---|
53 | * |
---|
54 | * Description: |
---|
55 | * This routine returns the smallest integer less than x. |
---|
56 | * |
---|
57 | *****************************************************************/ |
---|
58 | |
---|
59 | #include "fdlibm.h" |
---|
60 | #include "zmath.h" |
---|
61 | |
---|
62 | #ifndef _DOUBLE_IS_32BITS |
---|
63 | |
---|
64 | double |
---|
65 | floor (double x) |
---|
66 | { |
---|
67 | double f, y; |
---|
68 | |
---|
69 | if (x > -1.0 && x < 1.0) |
---|
70 | return (x >= 0 ? 0 : -1.0); |
---|
71 | |
---|
72 | y = modf (x, &f); |
---|
73 | |
---|
74 | if (y == 0.0) |
---|
75 | return (x); |
---|
76 | |
---|
77 | return (x >= 0 ? f : f - 1.0); |
---|
78 | } |
---|
79 | |
---|
80 | #endif /* _DOUBLE_IS_32BITS */ |
---|
Note: See
TracBrowser
for help on using the repository browser.