CVS update: php3/functions
| From: | ssb | Date: | Tue, 17 Nov 1998 09:48:13 +0000 |
| Subject: | CVS update: php3/functions | ||
| Groups: | php.dev | ||
| Request: | Send a blank email to php-dev+get-2434@lists.php.net to get a copy of this message | ||
Date: Tuesday November 17, 1998 @ 4:48
Author: ssb
Update of /repository/php3/functions
In directory asf:/u2/tmp/cvs-serv16599
Modified Files:
basic_functions.c phpmath.h math.c
Log Message:
Added base_convert() to convert numbers from any base <= 36 to any base <= 36.
Index: php3/functions/basic_functions.c
diff -c php3/functions/basic_functions.c:1.233 php3/functions/basic_functions.c:1.234
*** php3/functions/basic_functions.c:1.233 Tue Nov 10 19:10:26 1998
--- php3/functions/basic_functions.c Tue Nov 17 04:48:12 1998
***************
*** 252,257 ****
--- 252,258 ----
{"decbin", php3_decbin, NULL},
{"decoct", php3_decoct, NULL},
{"dechex", php3_dechex, NULL},
+ {"base_convert",php3_base_convert, NULL},
{"number_format", php3_number_format, NULL},
#if HAVE_PUTENV
Index: php3/functions/phpmath.h
diff -c php3/functions/phpmath.h:1.13 php3/functions/phpmath.h:1.14
*** php3/functions/phpmath.h:1.13 Wed Sep 23 21:06:51 1998
--- php3/functions/phpmath.h Tue Nov 17 04:48:12 1998
***************
*** 29,35 ****
*/
! /* $Id: phpmath.h,v 1.13 1998/09/24 01:06:51 rasmus Exp $ */
#ifndef _PHPMATH_H
#define _PHPMATH_H
--- 29,35 ----
*/
! /* $Id: phpmath.h,v 1.14 1998/11/17 09:48:12 ssb Exp $ */
#ifndef _PHPMATH_H
#define _PHPMATH_H
***************
*** 59,64 ****
--- 59,65 ----
extern void php3_bindec(INTERNAL_FUNCTION_PARAMETERS);
extern void php3_hexdec(INTERNAL_FUNCTION_PARAMETERS);
extern void php3_octdec(INTERNAL_FUNCTION_PARAMETERS);
+ extern void php3_base_convert(INTERNAL_FUNCTION_PARAMETERS);
extern void php3_number_format(INTERNAL_FUNCTION_PARAMETERS);
extern void php3_deg2rad(INTERNAL_FUNCTION_PARAMETERS);
extern void php3_rad2deg(INTERNAL_FUNCTION_PARAMETERS);
Index: php3/functions/math.c
diff -c php3/functions/math.c:1.40 php3/functions/math.c:1.41
*** php3/functions/math.c:1.40 Fri Nov 6 18:19:13 1998
--- php3/functions/math.c Tue Nov 17 04:48:13 1998
***************
*** 543,548 ****
--- 543,580 ----
} /* }}} */
+ /* {{{ proto string base_convert(string number, int frombase, int tobase)
+ Converts a number in a string from any base <= 36 to any base <= 36.
+ */
+ void php3_base_convert(INTERNAL_FUNCTION_PARAMETERS)
+ {
+ pval *number, *frombase, *tobase, temp;
+ char *result;
+
+ if (ARG_COUNT(ht) != 3 || getParameters(ht, 3, &number, &frombase, &tobase)
+ == FAILURE) {
+ WRONG_PARAM_COUNT;
+ }
+ convert_to_string(number);
+ convert_to_long(frombase);
+ convert_to_long(tobase);
+ if (frombase->value.lval < 2 || frombase->value.lval > 36) {
+ php3_error(E_WARNING, "base_convert: invalid `from base' (%d)",
+ frombase->value.lval);
+ RETURN_FALSE;
+ }
+ if (tobase->value.lval < 2 || tobase->value.lval > 36) {
+ php3_error(E_WARNING, "base_convert: invalid `to base' (%d)",
+ tobase->value.lval);
+ RETURN_FALSE;
+ }
+ temp.type = IS_LONG;
+ temp.value.lval = _php3_basetolong(number, frombase->value.lval);
+ result = _php3_longtobase(&temp, tobase->value.lval);
+ RETVAL_STRING(result, 0);
+ }
+
+
char *_php3_number_format(double d,int dec,char dec_point,char thousand_sep)
{
char *tmpbuf,*resbuf;
--
PHP Development Mailing List http://www.php.net/
To unsubscribe send an empty message to php-dev-unsubscribe@lists.php.net
For help: php-dev-help@lists.php.net