Changeset 1258
- Timestamp:
- 09/12/08 14:40:40 (3 months ago)
- Files:
-
- 1.8.3/branches/devel/CHANGES.183 (modified) (1 diff)
- 1.8.3/branches/devel/config.h.in (modified) (1 diff)
- 1.8.3/branches/devel/configure.in (modified) (1 diff)
- 1.8.3/branches/devel/game/txt/hlp/pennfunc.hlp (modified) (1 diff)
- 1.8.3/branches/devel/src/funmath.c (modified) (2 diffs)
- 1.8.3/branches/devel/test/testmath.pl (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
1.8.3/branches/devel/CHANGES.183
r1257 r1258 58 58 * cbufferadd() - Add text to a channel buffer without broadcasting it. 59 59 Allows for @chan/recall on an @chat that's been overridden. 60 * Rewrote the internals of round() to avoid some nasty kludges. [SW] 60 61 61 62 Fixes: 1.8.3/branches/devel/config.h.in
r1195 r1258 182 182 #undef HAVE_LOG2 183 183 184 #undef HAVE_ROUND 185 184 186 #undef HAS_CRYPT 185 187 1.8.3/branches/devel/configure.in
r1235 r1258 221 221 AC_FUNC_SETPGRP 222 222 fi 223 AC_CHECK_FUNCS([cbrt log2 getuid geteuid seteuid getpriority setpriority]) 224 AC_CHECK_FUNCS([socketpair sigaction sigprocmask imaxdiv valloc writev]) 223 AC_CHECK_FUNCS([cbrt log2 round imaxdiv]) 224 AC_CHECK_FUNCS([getuid geteuid seteuid getpriority setpriority]) 225 AC_CHECK_FUNCS([socketpair sigaction sigprocmask valloc writev]) 225 226 AC_CHECK_FUNCS([fcntl pselect poll ppoll pollts kqueue epoll_ctl inotify_init]) 226 227 1.8.3/branches/devel/game/txt/hlp/pennfunc.hlp
r1255 r1258 3410 3410 3411 3411 Rounds <number> to <places> decimal places. <places> must be between 3412 0 and 6.3412 0 and config(float_precision). 3413 3413 3414 3414 See also: ceil(), floor(), bound(), trunc() 1.8.3/branches/devel/src/funmath.c
r1243 r1258 899 899 } 900 900 901 double 902 fround(double n, int d) 903 { 904 double ex = pow(10.0, d); 905 return floor(n * ex + 0.5) / ex; 906 } 907 901 908 /* ARGSUSED */ 902 909 FUNCTION(fun_round) 903 910 { 904 char temp[BUFFER_LEN];905 911 int places; 912 double n, rounded; 906 913 907 914 if (!is_number(args[0])) { 908 915 safe_str(T(e_num), buff, bp); 909 916 return; 910 } 917 } else 918 n = parse_number(args[0]); 919 911 920 if (nargs == 2) { 912 921 if (!is_integer(args[1])) { … … 923 932 places = FLOAT_PRECISION; 924 933 925 /* The 0.0000001 is a kludge because .15 gets represented as .149999... 926 * on many systems, and rounds down to .1. Lame. */ 927 sprintf(temp, "%.*f", places, parse_number(args[0]) + 0.0000001); 928 929 /* Handle the bizarre "-0" sprintf problem. */ 930 if (!strcmp(temp, "-0")) 931 safe_chr('0', buff, bp); 934 #ifdef HAVE_ROUND 935 if (places == 0) 936 rounded = round(n); 932 937 else 933 safe_str(temp, buff, bp); 938 rounded = fround(n, places); 939 #else 940 rounded = fround(n, places); 941 #endif 942 943 safe_number(rounded, buff, bp); 934 944 } 935 945 1.8.3/branches/devel/test/testmath.pl
r1121 r1258 44 44 $god->command('@config/set float_precision=10'); 45 45 test('root.5', $god, 'think root(125, 5)', '2.6265278044'); 46 47 test('round.0', $god, 'think round(pi(), 0)', '3'); 48 test('round.1', $god, 'think round(pi(), 1)', '3.1'); 49 test('round.2', $god, 'think round(pi(), 2)', '3.14'); 50 test('round.3', $god, 'think round(pi(), 3)', '3.142'); 51 test('round.4', $god, 'think round(pi(), 4)', '3.1416'); 52 test('round.5', $god, 'think round(pi(), 5)', '3.14159'); 53 test('round.6', $god, 'think round(-[pi()], 3)', '-3.142');
