e576bb2002-10-11Martin Nilsson /* || This file is part of Pike. For copyright information see COPYRIGHT. || Pike is distributed under GPL, LGPL and MPL. See the file COPYING || for more information. */
1b10db2002-10-08Martin Nilsson 
fda0de1999-10-08Fredrik Noring #include "global.h" #include "interpret.h" #include "program.h" #include "object.h" #include "svalue.h"
b2d3e42000-12-01Fredrik Hübinette (Hubbe) #include "pike_error.h"
fda0de1999-10-08Fredrik Noring 
2b1c922013-12-24Henrik Grubbström (Grubba) #include "bignum.h"
1f21332000-07-28Fredrik Hübinette (Hubbe) PMOD_EXPORT void convert_stack_top_to_bignum(void)
e37a3e1999-10-09Fredrik Hübinette (Hubbe) {
07bb4a2014-10-29Martin Nilsson  push_object(clone_object(bignum_program, 1));
e37a3e1999-10-09Fredrik Hübinette (Hubbe) }
fda0de1999-10-08Fredrik Noring 
1f21332000-07-28Fredrik Hübinette (Hubbe) PMOD_EXPORT void convert_stack_top_with_base_to_bignum(void)
31ea271999-10-22Fredrik Noring {
07bb4a2014-10-29Martin Nilsson  push_object(clone_object(bignum_program, 2));
31ea271999-10-22Fredrik Noring }
1f21332000-07-28Fredrik Hübinette (Hubbe) PMOD_EXPORT int is_bignum_object_in_svalue(struct svalue *sv)
39ac731999-10-20Fredrik Noring {
6b304c2004-12-30Henrik Grubbström (Grubba)  /* FIXME: object subtype? */
017b572011-10-28Henrik Grubbström (Grubba)  return TYPEOF(*sv) == T_OBJECT && is_bignum_object(sv->u.object);
39ac731999-10-20Fredrik Noring }
e37a3e1999-10-09Fredrik Hübinette (Hubbe) 
1f21332000-07-28Fredrik Hübinette (Hubbe) PMOD_EXPORT struct object *make_bignum_object(void)
fda0de1999-10-08Fredrik Noring {
07bb4a2014-10-29Martin Nilsson  return clone_object(bignum_program, 1);
e37a3e1999-10-09Fredrik Hübinette (Hubbe) }
1f21332000-07-28Fredrik Hübinette (Hubbe) PMOD_EXPORT struct object *bignum_from_svalue(struct svalue *s)
e37a3e1999-10-09Fredrik Hübinette (Hubbe) { push_svalue(s);
07bb4a2014-10-29Martin Nilsson  return make_bignum_object();
fda0de1999-10-08Fredrik Noring }
1f21332000-07-28Fredrik Hübinette (Hubbe) PMOD_EXPORT void convert_svalue_to_bignum(struct svalue *s)
fda0de1999-10-08Fredrik Noring {
e37a3e1999-10-09Fredrik Hübinette (Hubbe)  push_svalue(s); convert_stack_top_to_bignum(); free_svalue(s);
95d4b22014-10-29Martin Nilsson  *s=Pike_sp[-1]; Pike_sp--; dmalloc_touch_svalue(Pike_sp);
fda0de1999-10-08Fredrik Noring }
15a8282017-05-08Henrik Grubbström (Grubba)  PMOD_EXPORT int low_compare_bignums(MP_INT *a, MP_INT *b) { return mpz_cmp(a, b); } PMOD_EXPORT int compare_bignums(struct object *a, struct object *b) { if (!is_bignum_object(a)) Pike_error("First object is not a bignum.\n"); if (!is_bignum_object(b)) Pike_error("Second object is not a bignum.\n"); return low_compare_bignums((MP_INT *)a->storage, (MP_INT *)b->storage); }