annotate src/libm/s_floor.c @ 4447:947201caa46e

Added automated test to Xcode project plus needed changes to SDL_RWFromFile to be OS X bundle aware. The Mac OS X project has a new target called testsdl which builds the automated test. I looked at using Xcode's native unit test support, but the impedance mismatch between the existing automated test structure and Apple's was more than I could handle. As such, the testsdl application is a full blown proper OS X application, which means it is a self-contained .app bundle. This immediately revealed some problems from the automated test. The largest problem was the assumption about the current working directory and where to find resources. (I suspect Windows may have a similar problem depending on circumstance.) To open resources, the test was looking in directories relative to the SDL source directory, but this will not work well with self-contained .app bundles and Xcode which can place its built applications almost anywhere. And for real-world situations, this is pretty useless anyway. So I modified SDL_RWFromFile to do special things on OS X. First, it will look for a file in the .app bundle. If not found, it will fallback and just call fopen as it used to do. I also had to modify the automated test itself because it had a contrieved test which called fopen directly to do read from an existing FILE pointer. In addition, there was a write test. Since a .app bundle is likely going to be read-only, I added a special case for OS X to write to NSTemporaryDirectory. I expect these changes should work for both Mac and iPhone OS (which includes iPad). I will update the iPhone Xcode project next. Finally, FYI, the X11 automated test seems to be failing. Below is my output. Pending breakpoint 4 - "-[NSException raise]" resolved Platform : All tests successful (2) SDL_RWops : All tests successful (5) Rect : All tests successful (1) SDL_Surface : All tests successful (6) Rendering with cocoa driver : All tests successful (3) Assert Failed! Blit output not the same. Test Case 'Renderer x11' Test Suite 'Rendering with x11 driver' Last SDL error '' Sat May 8 00:30:34 iMacAL.local testsdl[71586] <Error>: kCGErrorIllegalArgument: CGSGetSurfaceBounds Sat May 8 00:30:34 iMacAL.local testsdl[71586] <Error>: kCGErrorFailure: Set a breakpoint @ CGErrorBreakpoint() to catch errors as they are logged. Sat May 8 00:30:34 iMacAL.local testsdl[71586] <Error>: kCGErrorIllegalArgument: CGSBindSurface: Invalid window 0xa150 Sat May 8 00:30:34 iMacAL.local testsdl[71586] <Error>: kCGErrorIllegalArgument: CGSBindSurface: Invalid window 0xa150 Sat May 8 00:30:34 iMacAL.local testsdl[71586] <Error>: kCGErrorIllegalArgument: CGSBindSurface: Invalid window 0xa150 Sat May 8 00:30:34 iMacAL.local testsdl[71586] <Error>: kCGErrorIllegalArgument: CGSGetWindowBounds Sat May 8 00:30:34 iMacAL.local testsdl[71586] <Error>: kCGErrorIllegalArgument: CGSGetSurfaceBounds Sat May 8 00:30:34 iMacAL.local testsdl[71586] <Error>: kCGErrorIllegalArgument: CGSBindSurface: Invalid window 0xa150 Sat May 8 00:30:34 iMacAL.local testsdl[71586] <Error>: kCGErrorIllegalArgument: CGSBindSurface: Invalid window 0xa150 Sat May 8 00:30:34 iMacAL.local testsdl[71586] <Error>: kCGErrorIllegalArgument: CGSBindSurface: Invalid window 0xa150 Sat May 8 00:30:34 iMacAL.local testsdl[71586] <Error>: kCGErrorIllegalArgument: CGSGetWindowBounds Sat May 8 00:30:34 iMacAL.local testsdl[71586] <Error>: kCGErrorIllegalArgument: CGSGetSurfaceBounds Sat May 8 00:30:34 iMacAL.local testsdl[71586] <Error>: kCGErrorIllegalArgument: CGSBindSurface: Invalid window 0xa150 Sat May 8 00:30:34 iMacAL.local testsdl[71586] <Error>: kCGErrorIllegalArgument: CGSBindSurface: Invalid window 0xa150 Sat May 8 00:30:34 iMacAL.local testsdl[71586] <Error>: kCGErrorIllegalArgument: CGSBindSurface: Invalid window 0xa150 Sat May 8 00:30:34 iMacAL.local testsdl[71586] <Error>: kCGErrorIllegalArgument: CGSGetWindowBounds Sat May 8 00:30:34 iMacAL.local testsdl[71586] <Error>: kCGErrorIllegalArgument: CGSGetSurfaceBounds Sat May 8 00:30:34 iMacAL.local testsdl[71586] <Error>: kCGErrorIllegalArgument: CGSBindSurface: Invalid window 0xa150 Sat May 8 00:30:34 iMacAL.local testsdl[71586] <Error>: kCGErrorIllegalArgument: CGSBindSurface: Invalid window 0xa150 Sat May 8 00:30:34 iMacAL.local testsdl[71586] <Error>: kCGErrorIllegalArgument: CGSBindSurface: Invalid window 0xa150 Sat May 8 00:30:34 iMacAL.local testsdl[71586] <Error>: kCGErrorIllegalArgument: CGSGetWindowBounds Sat May 8 00:30:34 iMacAL.local testsdl[71586] <Error>: kCGErrorIllegalArgument: CGSGetSurfaceBounds Sat May 8 00:30:34 iMacAL.local testsdl[71586] <Error>: kCGErrorIllegalArgument: CGSBindSurface: Invalid window 0xa150 Sat May 8 00:30:34 iMacAL.local testsdl[71586] <Error>: kCGErrorIllegalArgument: CGSBindSurface: Invalid window 0xa150 Sat May 8 00:30:34 iMacAL.local testsdl[71586] <Error>: kCGErrorIllegalArgument: CGSBindSurface: Invalid window 0xa150 Sat May 8 00:30:34 iMacAL.local testsdl[71586] <Error>: kCGErrorIllegalArgument: CGSGetWindowBounds Sat May 8 00:30:34 iMacAL.local testsdl[71586] <Error>: kCGErrorIllegalArgument: CGSGetSurfaceBounds Sat May 8 00:30:34 iMacAL.local testsdl[71586] <Error>: kCGErrorIllegalArgument: CGSBindSurface: Invalid window 0xa150 Sat May 8 00:30:34 iMacAL.local testsdl[71586] <Error>: kCGErrorIllegalArgument: CGSBindSurface: Invalid window 0xa150 Sat May 8 00:30:34 iMacAL.local testsdl[71586] <Error>: kCGErrorIllegalArgument: CGSBindSurface: Invalid window 0xa150 Sat May 8 00:30:34 iMacAL.local testsdl[71586] <Error>: kCGErrorIllegalArgument: CGSGetWindowBounds Sat May 8 00:30:34 iMacAL.local testsdl[71586] <Error>: kCGErrorIllegalArgument: CGSGetSurfaceBounds Sat May 8 00:30:34 iMacAL.local testsdl[71586] <Error>: kCGErrorIllegalArgument: CGSBindSurface: Invalid window 0xa150 Sat May 8 00:30:34 iMacAL.local testsdl[71586] <Error>: kCGErrorIllegalArgument: CGSBindSurface: Invalid window 0xa150 Sat May 8 00:30:34 iMacAL.local testsdl[71586] <Error>: kCGErrorIllegalArgument: CGSBindSurface: Invalid window 0xa150 Rendering with x11 driver : Failed 1 out of 4 testcases! Rendering with dummy driver : All tests successful (3) SDL_Audio : All tests successful (1) Tests run with SDL 1.3.0 revision 1095906 System is running Mac OS X and is little endian
author Eric Wing <ewing . public |-at-| gmail . com>
date Sat, 08 May 2010 00:54:22 -0700
parents 9ac6f0782dd6
children
rev   line source
2758
045d9976f285 Yet more math...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1 /* @(#)s_floor.c 5.1 93/09/24 */
045d9976f285 Yet more math...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
2 /*
045d9976f285 Yet more math...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
3 * ====================================================
045d9976f285 Yet more math...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
4 * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
045d9976f285 Yet more math...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
5 *
045d9976f285 Yet more math...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
6 * Developed at SunPro, a Sun Microsystems, Inc. business.
045d9976f285 Yet more math...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
7 * Permission to use, copy, modify, and distribute this
045d9976f285 Yet more math...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
8 * software is freely granted, provided that this notice
045d9976f285 Yet more math...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
9 * is preserved.
045d9976f285 Yet more math...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
10 * ====================================================
045d9976f285 Yet more math...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
11 */
045d9976f285 Yet more math...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
12
045d9976f285 Yet more math...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
13 #if defined(LIBM_SCCS) && !defined(lint)
3162
dc1eb82ffdaa Von: Thomas Zimmermann
Sam Lantinga <slouken@libsdl.org>
parents: 2765
diff changeset
14 static const char rcsid[] =
2758
045d9976f285 Yet more math...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
15 "$NetBSD: s_floor.c,v 1.8 1995/05/10 20:47:20 jtc Exp $";
045d9976f285 Yet more math...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
16 #endif
045d9976f285 Yet more math...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
17
045d9976f285 Yet more math...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
18 /*
045d9976f285 Yet more math...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
19 * floor(x)
045d9976f285 Yet more math...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
20 * Return x rounded toward -inf to integral value
045d9976f285 Yet more math...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
21 * Method:
045d9976f285 Yet more math...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
22 * Bit twiddling.
045d9976f285 Yet more math...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
23 * Exception:
045d9976f285 Yet more math...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
24 * Inexact flag raised if x not equal to floor(x).
045d9976f285 Yet more math...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
25 */
045d9976f285 Yet more math...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
26
045d9976f285 Yet more math...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
27 #include "math.h"
045d9976f285 Yet more math...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
28 #include "math_private.h"
045d9976f285 Yet more math...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
29
045d9976f285 Yet more math...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
30 #ifdef __STDC__
3337
9ac6f0782dd6 Fixed bug #814
Sam Lantinga <slouken@libsdl.org>
parents: 3162
diff changeset
31 static const double huge_val = 1.0e300;
2758
045d9976f285 Yet more math...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
32 #else
3337
9ac6f0782dd6 Fixed bug #814
Sam Lantinga <slouken@libsdl.org>
parents: 3162
diff changeset
33 static double huge_val = 1.0e300;
2758
045d9976f285 Yet more math...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
34 #endif
045d9976f285 Yet more math...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
35
045d9976f285 Yet more math...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
36 libm_hidden_proto(floor)
045d9976f285 Yet more math...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
37 #ifdef __STDC__
045d9976f285 Yet more math...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
38 double floor(double x)
045d9976f285 Yet more math...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
39 #else
045d9976f285 Yet more math...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
40 double floor(x)
045d9976f285 Yet more math...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
41 double x;
045d9976f285 Yet more math...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
42 #endif
045d9976f285 Yet more math...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
43 {
045d9976f285 Yet more math...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
44 int32_t i0, i1, j0;
045d9976f285 Yet more math...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
45 u_int32_t i, j;
045d9976f285 Yet more math...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
46 EXTRACT_WORDS(i0, i1, x);
045d9976f285 Yet more math...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
47 j0 = ((i0 >> 20) & 0x7ff) - 0x3ff;
045d9976f285 Yet more math...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
48 if (j0 < 20) {
045d9976f285 Yet more math...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
49 if (j0 < 0) { /* raise inexact if x != 0 */
3337
9ac6f0782dd6 Fixed bug #814
Sam Lantinga <slouken@libsdl.org>
parents: 3162
diff changeset
50 if (huge_val + x > 0.0) { /* return 0*sign(x) if |x|<1 */
2758
045d9976f285 Yet more math...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
51 if (i0 >= 0) {
045d9976f285 Yet more math...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
52 i0 = i1 = 0;
045d9976f285 Yet more math...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
53 } else if (((i0 & 0x7fffffff) | i1) != 0) {
045d9976f285 Yet more math...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
54 i0 = 0xbff00000;
045d9976f285 Yet more math...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
55 i1 = 0;
045d9976f285 Yet more math...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
56 }
045d9976f285 Yet more math...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
57 }
045d9976f285 Yet more math...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
58 } else {
045d9976f285 Yet more math...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
59 i = (0x000fffff) >> j0;
045d9976f285 Yet more math...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
60 if (((i0 & i) | i1) == 0)
045d9976f285 Yet more math...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
61 return x; /* x is integral */
3337
9ac6f0782dd6 Fixed bug #814
Sam Lantinga <slouken@libsdl.org>
parents: 3162
diff changeset
62 if (huge_val + x > 0.0) { /* raise inexact flag */
2758
045d9976f285 Yet more math...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
63 if (i0 < 0)
045d9976f285 Yet more math...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
64 i0 += (0x00100000) >> j0;
045d9976f285 Yet more math...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
65 i0 &= (~i);
045d9976f285 Yet more math...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
66 i1 = 0;
045d9976f285 Yet more math...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
67 }
045d9976f285 Yet more math...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
68 }
045d9976f285 Yet more math...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
69 } else if (j0 > 51) {
045d9976f285 Yet more math...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
70 if (j0 == 0x400)
045d9976f285 Yet more math...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
71 return x + x; /* inf or NaN */
045d9976f285 Yet more math...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
72 else
045d9976f285 Yet more math...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
73 return x; /* x is integral */
045d9976f285 Yet more math...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
74 } else {
045d9976f285 Yet more math...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
75 i = ((u_int32_t) (0xffffffff)) >> (j0 - 20);
045d9976f285 Yet more math...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
76 if ((i1 & i) == 0)
045d9976f285 Yet more math...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
77 return x; /* x is integral */
3337
9ac6f0782dd6 Fixed bug #814
Sam Lantinga <slouken@libsdl.org>
parents: 3162
diff changeset
78 if (huge_val + x > 0.0) { /* raise inexact flag */
2758
045d9976f285 Yet more math...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
79 if (i0 < 0) {
045d9976f285 Yet more math...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
80 if (j0 == 20)
045d9976f285 Yet more math...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
81 i0 += 1;
045d9976f285 Yet more math...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
82 else {
045d9976f285 Yet more math...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
83 j = i1 + (1 << (52 - j0));
2765
f55c87ae336b Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents: 2760
diff changeset
84 if (j < (u_int32_t) i1)
2758
045d9976f285 Yet more math...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
85 i0 += 1; /* got a carry */
045d9976f285 Yet more math...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
86 i1 = j;
045d9976f285 Yet more math...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
87 }
045d9976f285 Yet more math...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
88 }
045d9976f285 Yet more math...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
89 i1 &= (~i);
045d9976f285 Yet more math...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
90 }
045d9976f285 Yet more math...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
91 }
045d9976f285 Yet more math...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
92 INSERT_WORDS(x, i0, i1);
045d9976f285 Yet more math...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
93 return x;
045d9976f285 Yet more math...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
94 }
045d9976f285 Yet more math...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
95
045d9976f285 Yet more math...
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
96 libm_hidden_def(floor)