Mercurial > hg > octave-nkf
comparison liboctave/lo-utils.cc @ 6490:0ad7655cf2bc
[project @ 2007-04-05 02:44:34 by jwe]
author | jwe |
---|---|
date | Thu, 05 Apr 2007 02:44:35 +0000 |
parents | e5ed0d1edddc |
children | 935d23e16951 |
comparison
equal
deleted
inserted
replaced
6489:39eb39d67dd8 | 6490:0ad7655cf2bc |
---|---|
24 | 24 |
25 #ifdef HAVE_CONFIG_H | 25 #ifdef HAVE_CONFIG_H |
26 #include <config.h> | 26 #include <config.h> |
27 #endif | 27 #endif |
28 | 28 |
29 #include <climits> | |
30 #include <cstdlib> | 29 #include <cstdlib> |
31 #include <cstdio> | 30 #include <cstdio> |
32 | 31 |
32 #include <limits> | |
33 #include <string> | 33 #include <string> |
34 | 34 |
35 #ifdef HAVE_UNISTD_H | 35 #ifdef HAVE_UNISTD_H |
36 #ifdef HAVE_SYS_TYPES_H | 36 #ifdef HAVE_SYS_TYPES_H |
37 #include <sys/types.h> | 37 #include <sys/types.h> |
46 | 46 |
47 // Convert X to the nearest integer value. Should not pass NaN to | 47 // Convert X to the nearest integer value. Should not pass NaN to |
48 // this function. | 48 // this function. |
49 | 49 |
50 // Sometimes you need a large integer, but not always. | 50 // Sometimes you need a large integer, but not always. |
51 // FIXME -- INT_MAX and INT_MIN are probably not right for 64-bits. | |
52 | 51 |
53 octave_idx_type | 52 octave_idx_type |
54 NINTbig (double x) | 53 NINTbig (double x) |
55 { | 54 { |
56 if (x > INT_MAX) | 55 if (x > std::numeric_limits<octave_idx_type>::max ()) |
57 return INT_MAX; | 56 return std::numeric_limits<octave_idx_type>::max (); |
58 else if (x < INT_MIN) | 57 else if (x < std::numeric_limits<octave_idx_type>::min ()) |
59 return INT_MIN; | 58 return std::numeric_limits<octave_idx_type>::min (); |
60 else | 59 else |
61 return static_cast<octave_idx_type> ((x > 0) ? (x + 0.5) : (x - 0.5)); | 60 return static_cast<octave_idx_type> ((x > 0) ? (x + 0.5) : (x - 0.5)); |
62 } | 61 } |
63 | 62 |
64 int | 63 int |
65 NINT (double x) | 64 NINT (double x) |
66 { | 65 { |
67 if (x > INT_MAX) | 66 if (x > std::numeric_limits<int>::max ()) |
68 return INT_MAX; | 67 return std::numeric_limits<int>::max (); |
69 else if (x < INT_MIN) | 68 else if (x < std::numeric_limits<int>::min ()) |
70 return INT_MIN; | 69 return std::numeric_limits<int>::min (); |
71 else | 70 else |
72 return static_cast<int> ((x > 0) ? (x + 0.5) : (x - 0.5)); | 71 return static_cast<int> ((x > 0) ? (x + 0.5) : (x - 0.5)); |
73 } | 72 } |
74 | 73 |
75 double | 74 double |