octave: recognize Python __float__ numeric conversion operator
This commit is contained in:
parent
697a1b7c9d
commit
000ab753df
4 changed files with 31 additions and 0 deletions
|
|
@ -26,4 +26,9 @@
|
|||
ComplexVal __paren__(int j) {
|
||||
return ComplexVal($self->re()*j,$self->im()*j);
|
||||
}
|
||||
|
||||
double __float__() {
|
||||
return (double) $self->re();
|
||||
}
|
||||
|
||||
};
|
||||
|
|
|
|||
|
|
@ -24,3 +24,7 @@ printf("a(3)= %s\n",disp(a(3)));
|
|||
|
||||
# friend operator
|
||||
printf("2*a = %s\n",disp(2*a));
|
||||
|
||||
# conversions
|
||||
printf("single(a) = %g\n", single(a));
|
||||
printf("double(a) = %g\n", double(a));
|
||||
|
|
|
|||
|
|
@ -816,6 +816,14 @@ SWIGRUNTIME void swig_acquire_ownership_obj(void *vptr, int own);
|
|||
return ret.string_value();
|
||||
}
|
||||
|
||||
virtual double scalar_value(bool frc_str_conv = false) const {
|
||||
octave_value ret;
|
||||
if (!dispatch_unary_op("__float__", ret)) {
|
||||
error("__float__ method not defined");
|
||||
}
|
||||
return ret.scalar_value();
|
||||
}
|
||||
|
||||
#if SWIG_OCTAVE_PREREQ(3,3,52)
|
||||
virtual octave_map map_value() const {
|
||||
return octave_map();
|
||||
|
|
@ -1069,6 +1077,9 @@ SWIGRUNTIME void swig_acquire_ownership_obj(void *vptr, int own);
|
|||
virtual std::string string_value(bool force = false) const
|
||||
{ return ptr->string_value(force); }
|
||||
|
||||
virtual double scalar_value(bool frc_str_conv = false) const
|
||||
{ return ptr->scalar_value(frc_str_conv); }
|
||||
|
||||
#if SWIG_OCTAVE_PREREQ(3,3,52)
|
||||
virtual octave_map map_value() const
|
||||
{ return ptr->map_value(); }
|
||||
|
|
@ -1126,7 +1137,17 @@ SWIGRUNTIME void swig_acquire_ownership_obj(void *vptr, int own);
|
|||
#endif
|
||||
{ return ptr->print(os, pr_as_read_syntax); }
|
||||
|
||||
virtual type_conv_info numeric_conversion_function(void) const {
|
||||
return octave_base_value::type_conv_info (default_numeric_conversion_function,
|
||||
octave_scalar::static_type_id ());
|
||||
}
|
||||
|
||||
private:
|
||||
static octave_base_value *default_numeric_conversion_function (const octave_base_value& a) {
|
||||
const octave_swig_ref& v = dynamic_cast<const octave_swig_ref&>(a);
|
||||
return new octave_scalar(v.scalar_value());
|
||||
}
|
||||
|
||||
#if !SWIG_OCTAVE_PREREQ(4,0,0)
|
||||
DECLARE_OCTAVE_ALLOCATOR;
|
||||
#endif
|
||||
|
|
|
|||
|
|
@ -6,6 +6,7 @@
|
|||
#include <octave/dynamic-ld.h>
|
||||
#include <octave/oct-env.h>
|
||||
#include <octave/oct-map.h>
|
||||
#include <octave/ov-scalar.h>
|
||||
#include <octave/ov-fcn-handle.h>
|
||||
#include <octave/parse.h>
|
||||
#include <octave/toplev.h>
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue