Permalink
Switch branches/tags
Nothing to show
Find file
Fetching contributors…
Cannot retrieve contributors at this time
1448 lines (1048 sloc) 34.1 KB
/*
Copyright (C) 2005-2009, Parrot Foundation.
$Id$
=head1 Lua Number
=head2 Description
C<LuaNumber> extends C<LuaAny> to provide a class with the behaviour of
the Lua C<Number> type.
=head3 Overloaded Methods
=over 4
=cut
*/
#include "lua_private.h"
#define LUA_NUMBER_FMT "%.14g"
pmclass LuaNumber
extends LuaAny
provides scalar
provides float
auto_attrs
dynpmc
group lua_group
hll lua
maps Integer
maps Float {
ATTR FLOATVAL fv;
/*
=item C<void init()>
Initializes the number to zero.
=cut
*/
VTABLE void init() {
SET_ATTR_fv(INTERP, SELF, 0.0);
}
/*
=item C<STRING* name()>
Return the string "number".
=cut
*/
VTABLE STRING* name() {
return Parrot_str_new_constant(INTERP, "number");
}
/*
=item C<PMC *clone()>
Creates and returns a clone of the scalar.
=cut
*/
VTABLE PMC *clone() {
FLOATVAL fv;
PMC * const dest = Parrot_pmc_new(INTERP, PMC_type(SELF));
GET_ATTR_fv(INTERP, SELF, fv);
SET_ATTR_fv(INTERP, dest, fv);
return dest;
}
/*
=item C<INTVAL get_integer()>
Returns an integer representation of the number (by casting).
=cut
*/
VTABLE INTVAL get_integer() {
FLOATVAL fv;
GET_ATTR_fv(INTERP, SELF, fv);
return (INTVAL) fv;
}
/*
=item C<FLOATVAL get_number()>
Returns the value of the number.
=cut
*/
VTABLE FLOATVAL get_number() {
FLOATVAL fv;
GET_ATTR_fv(INTERP, SELF, fv);
return fv;
}
/*
=item C<STRING* get_string()>
Returns a Parrot string representation of the number.
=cut
*/
VTABLE STRING* get_string() {
const FLOATVAL fv = SELF.get_number();
return Parrot_sprintf_c(INTERP, LUA_NUMBER_FMT, fv);
}
/*
=item C<void set_integer_native(INTVAL value)>
=cut
*/
VTABLE void set_integer_native(INTVAL value) {
SET_ATTR_fv(INTERP, SELF, (FLOATVAL)value);
}
/*
=item C<void set_number_native(FLOATVAL value)>
=cut
*/
VTABLE void set_number_native(FLOATVAL value) {
SET_ATTR_fv(INTERP, SELF, value);
}
/*
=item C<VOID set_string_native(STRING* value)>
=cut
*/
VTABLE void set_string_native(STRING *value) {
Parrot_pmc_reuse(INTERP, SELF, dynpmc_LuaString, 0);
SELF.set_string_native(value);
}
/*
=item C<void set_pmc(PMC *value)>
Sets the value of the number to the value in C<*value>.
=cut
*/
VTABLE void set_pmc(PMC *value) {
SET_ATTR_fv(INTERP, SELF, VTABLE_get_number(INTERP, value));
}
/*
=item C<void increment()>
Increments the number.
=cut
*/
VTABLE void increment() {
FLOATVAL fv;
GET_ATTR_fv(INTERP, SELF, fv);
fv++;
SET_ATTR_fv(INTERP, SELF, fv);
}
/*
=item C<void decrement()>
Decrements the number.
=cut
*/
VTABLE void decrement() {
FLOATVAL fv;
GET_ATTR_fv(INTERP, SELF, fv);
fv--;
SET_ATTR_fv(INTERP, SELF, fv);
}
/*
=item C<PMC *neg(PMC *dest)>
=cut
*/
VTABLE PMC *neg(PMC *dest) {
const FLOATVAL n = - SELF.get_number();
dest = Parrot_pmc_new(INTERP, dynpmc_LuaNumber);
VTABLE_set_number_native(INTERP, dest, n);
return dest;
}
/*
=item C<void i_neg()>
=cut
*/
VTABLE void i_neg() {
const FLOATVAL n = - SELF.get_number();
SELF.set_number_native(n);
}
/*
=item C<void freeze(PMC *info)>
Used to archive the number.
=cut
*/
VTABLE void freeze(PMC *info) {
SUPER(info);
VTABLE_push_float(INTERP, info, SELF.get_number());
}
/*
=item C<void thaw(PMC *info)>
Used to unarchive the number.
=cut
*/
VTABLE void thaw(PMC *info) {
SUPER(info);
SET_ATTR_fv(INTERP, SELF, VTABLE_shift_float(INTERP, info));
}
/*
/*
=back
=head3 non-Vtable Methods
=over 4
=item C<PMC *add(PMC *value, PMC *dest)>
=cut
*/
MULTI PMC *add(LuaNumber value, PMC *dest) {
const FLOATVAL n = SELF.get_number()
+ VTABLE_get_number(INTERP, value);
dest = Parrot_pmc_new(INTERP, dynpmc_LuaNumber);
VTABLE_set_number_native(INTERP, dest, n);
return dest;
}
MULTI PMC *add(LuaString value, PMC *dest) {
PMC *n;
Parrot_pcc_invoke_method_from_c_args(INTERP, value,
Parrot_str_new_constant(INTERP, "tonumber"), "->P", &n);
if (PMC_type(n) == dynpmc_LuaNumber)
return Parrot_LuaNumber_multi_add_LuaNumber_PMC(INTERP, SELF, n, dest);
Parrot_ex_throw_from_c_args(INTERP, NULL, EXCEPTION_ILL_INHERIT,
"attempt to perform arithmetic on a %Ss value",
VTABLE_name(INTERP, value));
}
MULTI PMC *add(DEFAULT value, PMC *dest) {
PMC * const meth = _LuaAny_find_meth(INTERP, value, "__add");
if (!PMC_IS_NULL(meth)) {
Parrot_ext_call(INTERP, meth, "PiP->P", SELF, value, &dest);
if (PMC_IS_NULL(dest))
dest = Parrot_pmc_new(INTERP, dynpmc_LuaNil);
return dest;
}
Parrot_ex_throw_from_c_args(INTERP, NULL, EXCEPTION_ILL_INHERIT,
"attempt to perform arithmetic on a %Ss value",
VTABLE_name(INTERP, value));
}
/*
=item C<void i_add(PMC *value)>
=cut
*/
MULTI void i_add(LuaNumber value) {
const FLOATVAL n = SELF.get_number()
+ VTABLE_get_number(INTERP, value);
SELF.set_number_native(n);
}
MULTI void i_add(LuaString value) {
PMC *n;
Parrot_pcc_invoke_method_from_c_args(INTERP, value,
Parrot_str_new_constant(INTERP, "tonumber"), "->P", &n);
if (PMC_type(n) == dynpmc_LuaNumber)
Parrot_LuaNumber_multi_i_add_LuaNumber(INTERP, SELF, n);
else
Parrot_ex_throw_from_c_args(INTERP, NULL, EXCEPTION_ILL_INHERIT,
"attempt to perform arithmetic on a %Ss value",
VTABLE_name(INTERP, value));
}
MULTI void i_add(DEFAULT value) {
PMC * const meth = _LuaAny_find_meth(INTERP, value, "__add");
if (!PMC_IS_NULL(meth)) {
Parrot_ext_call(INTERP, meth, "PiP->P", SELF, value, &SELF);
if (PMC_IS_NULL(SELF))
SELF = Parrot_pmc_new(INTERP, dynpmc_LuaNil);
return;
}
Parrot_ex_throw_from_c_args(INTERP, NULL, EXCEPTION_ILL_INHERIT,
"attempt to perform arithmetic on a %Ss value",
VTABLE_name(INTERP, value));
}
/*
=item C<PMC *subtract(PMC *value, PMC *dest)>
=cut
*/
MULTI PMC *subtract(LuaNumber value, PMC *dest) {
const FLOATVAL n = SELF.get_number()
- VTABLE_get_number(INTERP, value);
dest = Parrot_pmc_new(INTERP, dynpmc_LuaNumber);
VTABLE_set_number_native(INTERP, dest, n);
return dest;
}
MULTI PMC *subtract(LuaString value, PMC *dest) {
PMC *n;
Parrot_pcc_invoke_method_from_c_args(INTERP, value,
Parrot_str_new_constant(INTERP, "tonumber"), "->P", &n);
if (PMC_type(n) == dynpmc_LuaNumber)
return Parrot_LuaNumber_multi_subtract_LuaNumber_PMC(INTERP, SELF, n, dest);
Parrot_ex_throw_from_c_args(INTERP, NULL, EXCEPTION_ILL_INHERIT,
"attempt to perform arithmetic on a %Ss value",
VTABLE_name(INTERP, value));
}
MULTI PMC *subtract(DEFAULT value, PMC *dest) {
PMC * const meth = _LuaAny_find_meth(INTERP, value, "__sub");
if (!PMC_IS_NULL(meth)) {
Parrot_ext_call(INTERP, meth, "PiP->P", SELF, value, &dest);
if (PMC_IS_NULL(dest)) {
dest = Parrot_pmc_new(INTERP, dynpmc_LuaNil);
}
return dest;
}
Parrot_ex_throw_from_c_args(INTERP, NULL, EXCEPTION_ILL_INHERIT,
"attempt to perform arithmetic on a %Ss value",
VTABLE_name(INTERP, value));
}
/*
=item C<void i_subtract(PMC *value)>
=cut
*/
MULTI void i_subtract(LuaNumber value) {
const FLOATVAL n = SELF.get_number()
- VTABLE_get_number(INTERP, value);
SELF.set_number_native(n);
}
MULTI void i_subtract(LuaString value) {
PMC *n;
Parrot_pcc_invoke_method_from_c_args(INTERP, value,
Parrot_str_new_constant(INTERP, "tonumber"), "->P", &n);
if (PMC_type(n) == dynpmc_LuaNumber)
Parrot_LuaNumber_multi_i_subtract_LuaNumber(INTERP, SELF, n);
else
Parrot_ex_throw_from_c_args(INTERP, NULL, EXCEPTION_ILL_INHERIT,
"attempt to perform arithmetic on a %Ss value",
VTABLE_name(INTERP, value));
}
MULTI void i_subtract(DEFAULT value) {
PMC * const meth = _LuaAny_find_meth(INTERP, value, "__sub");
if (!PMC_IS_NULL(meth)) {
Parrot_ext_call(INTERP, meth, "PiP->P", SELF, value, &SELF);
if (PMC_IS_NULL(SELF))
SELF = Parrot_pmc_new(INTERP, dynpmc_LuaNil);
return;
}
Parrot_ex_throw_from_c_args(INTERP, NULL, EXCEPTION_ILL_INHERIT,
"attempt to perform arithmetic on a %Ss value",
VTABLE_name(INTERP, value));
}
/*
=item C<PMC *multiply(PMC *value, PMC *dest)>
=cut
*/
MULTI PMC *multiply(LuaNumber value, PMC *dest) {
const FLOATVAL n = SELF.get_number()
* VTABLE_get_number(INTERP, value);
dest = Parrot_pmc_new(INTERP, dynpmc_LuaNumber);
VTABLE_set_number_native(INTERP, dest, n);
return dest;
}
MULTI PMC *multiply(LuaString value, PMC *dest) {
PMC *n;
Parrot_pcc_invoke_method_from_c_args(INTERP, value,
Parrot_str_new_constant(INTERP, "tonumber"), "->P", &n);
if (PMC_type(n) == dynpmc_LuaNumber)
return Parrot_LuaNumber_multi_multiply_LuaNumber_PMC(INTERP, SELF, n, dest);
Parrot_ex_throw_from_c_args(INTERP, NULL, EXCEPTION_ILL_INHERIT,
"attempt to perform arithmetic on a %Ss value",
VTABLE_name(INTERP, value));
}
MULTI PMC *multiply(DEFAULT value, PMC *dest) {
PMC * const meth = _LuaAny_find_meth(INTERP, value, "__mul");
if (!PMC_IS_NULL(meth)) {
Parrot_ext_call(INTERP, meth, "PiP->P", SELF, value, &dest);
if (PMC_IS_NULL(dest))
dest = Parrot_pmc_new(INTERP, dynpmc_LuaNil);
return dest;
}
Parrot_ex_throw_from_c_args(INTERP, NULL, EXCEPTION_ILL_INHERIT,
"attempt to perform arithmetic on a %Ss value",
VTABLE_name(INTERP, value));
}
/*
=item C<void i_multiply(PMC *value)>
=cut
*/
MULTI void i_multiply(LuaNumber value) {
const FLOATVAL n = SELF.get_number() * VTABLE_get_number(INTERP, value);
SELF.set_number_native(n);
}
MULTI void i_multiply(LuaString value) {
PMC *n;
Parrot_pcc_invoke_method_from_c_args(INTERP, value,
Parrot_str_new_constant(INTERP, "tonumber"), "->P", &n);
if (PMC_type(n) == dynpmc_LuaNumber)
Parrot_LuaNumber_multi_i_multiply_LuaNumber(INTERP, SELF, n);
else
Parrot_ex_throw_from_c_args(INTERP, NULL, EXCEPTION_ILL_INHERIT,
"attempt to perform arithmetic on a %Ss value",
VTABLE_name(INTERP, value));
}
MULTI void i_multiply(DEFAULT value) {
PMC * const meth = _LuaAny_find_meth(INTERP, value, "__mul");
if (!PMC_IS_NULL(meth)) {
Parrot_ext_call(INTERP, meth, "PiP->P", SELF, value, &SELF);
if (PMC_IS_NULL(SELF))
SELF = Parrot_pmc_new(INTERP, dynpmc_LuaNil);
return;
}
Parrot_ex_throw_from_c_args(INTERP, NULL, EXCEPTION_ILL_INHERIT,
"attempt to perform arithmetic on a %Ss value",
VTABLE_name(INTERP, value));
}
/*
=item C<PMC *divide(PMC *value, PMC *dest)>
=cut
*/
MULTI PMC *divide(LuaNumber value, PMC *dest) {
const FLOATVAL n = SELF.get_number()
/ VTABLE_get_number(INTERP, value);
dest = Parrot_pmc_new(INTERP, dynpmc_LuaNumber);
VTABLE_set_number_native(INTERP, dest, n);
return dest;
}
MULTI PMC *divide(LuaString value, PMC *dest) {
PMC *n;
Parrot_pcc_invoke_method_from_c_args(INTERP, value,
Parrot_str_new_constant(INTERP, "tonumber"), "->P", &n);
if (PMC_type(n) == dynpmc_LuaNumber)
return Parrot_LuaNumber_multi_divide_LuaNumber_PMC(INTERP, SELF, n, dest);
Parrot_ex_throw_from_c_args(INTERP, NULL, EXCEPTION_ILL_INHERIT,
"attempt to perform arithmetic on a %Ss value",
VTABLE_name(INTERP, value));
}
MULTI PMC *divide(DEFAULT value, PMC *dest) {
PMC * const meth = _LuaAny_find_meth(INTERP, value, "__div");
if (!PMC_IS_NULL(meth)) {
Parrot_ext_call(INTERP, meth, "PiP->P", SELF, value, &dest);
if (PMC_IS_NULL(dest))
dest = Parrot_pmc_new(INTERP, dynpmc_LuaNil);
return dest;
}
Parrot_ex_throw_from_c_args(INTERP, NULL, EXCEPTION_ILL_INHERIT,
"attempt to perform arithmetic on a %Ss value",
VTABLE_name(INTERP, value));
}
/*
=item C<void i_divide(PMC *value)>
=cut
*/
MULTI void i_divide(LuaNumber value) {
const FLOATVAL n = SELF.get_number()
/ VTABLE_get_number(INTERP, value);
SELF.set_number_native(n);
}
MULTI void i_divide(LuaString value) {
PMC *n;
Parrot_pcc_invoke_method_from_c_args(INTERP, value,
Parrot_str_new_constant(INTERP, "tonumber"), "->P", &n);
if (PMC_type(n) == dynpmc_LuaNumber)
Parrot_LuaNumber_multi_i_divide_LuaNumber(INTERP, SELF, n);
else
Parrot_ex_throw_from_c_args(INTERP, NULL, EXCEPTION_ILL_INHERIT,
"attempt to perform arithmetic on a %Ss value",
VTABLE_name(INTERP, value));
}
MULTI void i_divide(DEFAULT value) {
PMC * const meth = _LuaAny_find_meth(INTERP, value, "__div");
if (!PMC_IS_NULL(meth)) {
Parrot_ext_call(INTERP, meth, "PiP->P", SELF, value, &SELF);
if (PMC_IS_NULL(SELF))
SELF = Parrot_pmc_new(INTERP, dynpmc_LuaNil);
return;
}
Parrot_ex_throw_from_c_args(INTERP, NULL, EXCEPTION_ILL_INHERIT,
"attempt to perform arithmetic on a %Ss value",
VTABLE_name(INTERP, value));
}
/*
=item C<PMC *modulus(PMC *value, PMC *dest)>
=cut
*/
MULTI PMC *modulus(LuaNumber value, PMC *dest) {
const FLOATVAL a = SELF.get_number();
const FLOATVAL b = VTABLE_get_number(INTERP, value);
const FLOATVAL n = a - floor(a / b) * b;
dest = Parrot_pmc_new(INTERP, dynpmc_LuaNumber);
VTABLE_set_number_native(INTERP, dest, n);
return dest;
}
MULTI PMC *modulus(LuaString value, PMC *dest) {
PMC *n;
Parrot_pcc_invoke_method_from_c_args(INTERP, value,
Parrot_str_new_constant(INTERP, "tonumber"), "->P", &n);
if (PMC_type(n) == dynpmc_LuaNumber)
return Parrot_LuaNumber_multi_modulus_LuaNumber_PMC(INTERP, SELF, n, dest);
Parrot_ex_throw_from_c_args(INTERP, NULL, EXCEPTION_ILL_INHERIT,
"attempt to perform arithmetic on a %Ss value",
VTABLE_name(INTERP, value));
}
MULTI PMC *modulus(DEFAULT value, PMC *dest) {
PMC * const meth = _LuaAny_find_meth(INTERP, value, "__mod");
if (!PMC_IS_NULL(meth)) {
Parrot_ext_call(INTERP, meth, "PiP->P", SELF, value, &dest);
if (PMC_IS_NULL(dest))
dest = Parrot_pmc_new(INTERP, dynpmc_LuaNil);
return dest;
}
Parrot_ex_throw_from_c_args(INTERP, NULL, EXCEPTION_ILL_INHERIT,
"attempt to perform arithmetic on a %Ss value",
VTABLE_name(INTERP, value));
}
/*
=item C<void i_modulus(PMC *value)>
=cut
*/
MULTI void i_modulus(LuaNumber value) {
const FLOATVAL a = SELF.get_number();
const FLOATVAL b = VTABLE_get_number(INTERP, value);
const FLOATVAL n = a - floor(a / b) * b;
SELF.set_number_native(n);
}
MULTI void i_modulus(LuaString value) {
PMC *n;
Parrot_pcc_invoke_method_from_c_args(INTERP, value,
Parrot_str_new_constant(INTERP, "tonumber"), "->P", &n);
if (PMC_type(n) == dynpmc_LuaNumber)
Parrot_LuaNumber_multi_i_modulus_LuaNumber(INTERP, SELF, n);
else
Parrot_ex_throw_from_c_args(INTERP, NULL, EXCEPTION_ILL_INHERIT,
"attempt to perform arithmetic on a %Ss value",
VTABLE_name(INTERP, value));
}
MULTI void i_modulus(DEFAULT value) {
PMC * const meth = _LuaAny_find_meth(INTERP, value, "__mod");
if (!PMC_IS_NULL(meth)) {
Parrot_ext_call(INTERP, meth, "PiP->P", SELF, value, &SELF);
if (PMC_IS_NULL(SELF))
SELF = Parrot_pmc_new(INTERP, dynpmc_LuaNil);
return;
}
Parrot_ex_throw_from_c_args(INTERP, NULL, EXCEPTION_ILL_INHERIT,
"attempt to perform arithmetic on a %Ss value",
VTABLE_name(INTERP, value));
}
/*
=item C<INTVAL is_equal(PMC *value)>
=cut
*/
MULTI INTVAL is_equal(LuaNumber value) {
return (INTVAL)(SELF.get_number() == VTABLE_get_number(INTERP, value));
}
MULTI INTVAL is_equal(DEFAULT value) {
return (INTVAL)0;
}
/*
=item C<INTVAL cmp(PMC *value)>
=cut
*/
MULTI INTVAL cmp(LuaNumber value) {
const FLOATVAL diff = SELF.get_number() - VTABLE_get_number(INTERP, value);
return diff > 0 ? 1 : diff < 0 ? -1 : 0;
}
MULTI INTVAL cmp(DEFAULT value) {
Parrot_ex_throw_from_c_args(INTERP, NULL, EXCEPTION_ILL_INHERIT,
"attempt to compare number with %Ss",
VTABLE_name(INTERP, value));
}
/*
=item C<PMC *concatenate(PMC *value, PMC *dest)>
=cut
*/
MULTI PMC *concatenate(LuaNumber value, PMC *dest) {
STRING * const s = Parrot_str_concat(INTERP, SELF.get_string(),
VTABLE_get_string(INTERP, value));
dest = Parrot_pmc_new(INTERP, dynpmc_LuaNumber);
VTABLE_set_string_native(INTERP, dest, s);
return dest;
}
MULTI PMC *concatenate(LuaString value, PMC *dest) {
STRING * const s = Parrot_str_concat(INTERP, SELF.get_string(),
VTABLE_get_string(INTERP, value));
dest = Parrot_pmc_new(INTERP, dynpmc_LuaNumber);
VTABLE_set_string_native(INTERP, dest, s);
return dest;
}
MULTI PMC *concatenate(DEFAULT value, PMC *dest) {
PMC * const meth = _LuaAny_find_meth(INTERP, value, "__concat");
if (!PMC_IS_NULL(meth)) {
Parrot_ext_call(INTERP, meth, "PiP->P", SELF, value, &dest);
if (PMC_IS_NULL(dest))
dest = Parrot_pmc_new(INTERP, dynpmc_LuaNil);
return dest;
}
Parrot_ex_throw_from_c_args(INTERP, NULL, EXCEPTION_ILL_INHERIT,
"attempt to concatenate a %Ss value",
VTABLE_name(INTERP, value));
}
/*
=item C<void i_concatenate(PMC *value)>
=cut
*/
MULTI void i_concatenate(LuaNumber value) {
STRING * const s = SELF.get_string();
STRING * const v = VTABLE_get_string(INTERP, value);
SELF.set_string_native(Parrot_str_concat(INTERP, s, v));
}
MULTI void i_concatenate(LuaString value) {
STRING * const s = SELF.get_string();
STRING * const v = VTABLE_get_string(INTERP, value);
SELF.set_string_native(Parrot_str_concat(INTERP, s, v));
}
MULTI void i_concatenate(DEFAULT value) {
PMC * const meth = _LuaAny_find_meth(INTERP, value, "__concat");
if (!PMC_IS_NULL(meth)) {
Parrot_ext_call(INTERP, meth, "PiP->P", SELF, value, &SELF);
if (PMC_IS_NULL(SELF))
SELF = Parrot_pmc_new(INTERP, dynpmc_LuaNil);
return;
}
Parrot_ex_throw_from_c_args(INTERP, NULL, EXCEPTION_ILL_INHERIT,
"attempt to concatenate a %Ss value",
VTABLE_name(INTERP, value));
}
/*
=back
=head3 Specific Methods
=over 4
=item C<PMC* acosh()>
=cut
*/
METHOD PMC* acosh() {
const FLOATVAL n = acosh(VTABLE_get_number(INTERP, SELF));
PMC * const retval = Parrot_pmc_new(INTERP, dynpmc_LuaNumber);
VTABLE_set_number_native(INTERP, retval, n);
RETURN(PMC *retval);
}
/*
=item C<PMC* asinh()>
=cut
*/
METHOD PMC* asinh() {
const FLOATVAL n = asinh(VTABLE_get_number(INTERP, SELF));
PMC * const retval = Parrot_pmc_new(INTERP, dynpmc_LuaNumber);
VTABLE_set_number_native(INTERP, retval, n);
RETURN(PMC *retval);
}
/*
=item C<PMC* atanh()>
=cut
*/
METHOD PMC* atanh() {
const FLOATVAL n = atanh(VTABLE_get_number(INTERP, SELF));
PMC * const retval = Parrot_pmc_new(INTERP, dynpmc_LuaNumber);
VTABLE_set_number_native(INTERP, retval, n);
RETURN(PMC *retval);
}
/*
=item C<PMC* cbrt()>
=cut
*/
METHOD PMC* cbrt() {
const FLOATVAL n = cbrt(VTABLE_get_number(INTERP, SELF));
PMC * const retval = Parrot_pmc_new(INTERP, dynpmc_LuaNumber);
VTABLE_set_number_native(INTERP, retval, n);
RETURN(PMC *retval);
}
/*
=item C<PMC* copysign(PMC* y)>
=cut
*/
METHOD PMC* copysign(PMC* y) {
const FLOATVAL n = copysign(VTABLE_get_number(INTERP, SELF),
VTABLE_get_number(INTERP, y));
PMC * const retval = Parrot_pmc_new(INTERP, dynpmc_LuaNumber);
VTABLE_set_number_native(INTERP, retval, n);
RETURN(PMC *retval);
}
/*
=item C<PMC* cosh()>
=cut
*/
METHOD PMC* cosh() {
const FLOATVAL n = cosh(VTABLE_get_number(INTERP, SELF));
PMC * const retval = Parrot_pmc_new(INTERP, dynpmc_LuaNumber);
VTABLE_set_number_native(INTERP, retval, n);
RETURN(PMC *retval);
}
/*
=item C<PMC* erf()>
=cut
*/
METHOD PMC* erf() {
const FLOATVAL n = erf(VTABLE_get_number(INTERP, SELF));
PMC * const retval = Parrot_pmc_new(INTERP, dynpmc_LuaNumber);
VTABLE_set_number_native(INTERP, retval, n);
RETURN(PMC *retval);
}
/*
=item C<PMC* erfc()>
=cut
*/
METHOD PMC* erfc() {
const FLOATVAL n = erfc(VTABLE_get_number(INTERP, SELF));
PMC * const retval = Parrot_pmc_new(INTERP, dynpmc_LuaNumber);
VTABLE_set_number_native(INTERP, retval, n);
RETURN(PMC *retval);
}
/*
=item C<PMC* exp2()>
=cut
*/
METHOD PMC* exp2() {
const FLOATVAL n = exp2(VTABLE_get_number(INTERP, SELF));
PMC * const retval = Parrot_pmc_new(INTERP, dynpmc_LuaNumber);
VTABLE_set_number_native(INTERP, retval, n);
RETURN(PMC *retval);
}
/*
=item C<PMC* expm1()>
=cut
*/
METHOD PMC* expm1() {
const FLOATVAL n = expm1(VTABLE_get_number(INTERP, SELF));
PMC * const retval = Parrot_pmc_new(INTERP, dynpmc_LuaNumber);
VTABLE_set_number_native(INTERP, retval, n);
RETURN(PMC *retval);
}
/*
=item C<PMC* fdim(PMC* y)>
=cut
*/
METHOD PMC* fdim(PMC* y) {
const FLOATVAL n = fdim(VTABLE_get_number(INTERP, SELF),
VTABLE_get_number(INTERP, y));
PMC * const retval = Parrot_pmc_new(INTERP, dynpmc_LuaNumber);
VTABLE_set_number_native(INTERP, retval, n);
RETURN(PMC *retval);
}
/*
=item C<PMC* fma(PMC* y, PMC* z)>
=cut
*/
METHOD PMC* fma(PMC* y, PMC* z) {
const FLOATVAL n = fma(VTABLE_get_number(INTERP, SELF),
VTABLE_get_number(INTERP, y),
VTABLE_get_number(INTERP, z));
PMC * const retval = Parrot_pmc_new(INTERP, dynpmc_LuaNumber);
VTABLE_set_number_native(INTERP, retval, n);
RETURN(PMC *retval);
}
/*
=item C<PMC* fmax(PMC* y)>
=cut
*/
METHOD PMC* fmax(PMC* y) {
const FLOATVAL n = fmax(VTABLE_get_number(INTERP, SELF),
VTABLE_get_number(INTERP, y));
PMC * const retval = Parrot_pmc_new(INTERP, dynpmc_LuaNumber);
VTABLE_set_number_native(INTERP, retval, n);
RETURN(PMC *retval);
}
/*
=item C<PMC* fmin(PMC* y)>
=cut
*/
METHOD PMC* fmin(PMC* y) {
const FLOATVAL n = fmin(VTABLE_get_number(INTERP, SELF),
VTABLE_get_number(INTERP, y));
PMC * const retval = Parrot_pmc_new(INTERP, dynpmc_LuaNumber);
VTABLE_set_number_native(INTERP, retval, n);
RETURN(PMC *retval);
}
/*
=item C<PMC* fpclassify()>
=cut
*/
METHOD PMC* fpclassify() {
PMC * const retval = Parrot_pmc_new(INTERP, dynpmc_LuaString);
const char *p;
switch (fpclassify(VTABLE_get_number(INTERP, SELF))) {
case FP_INFINITE: p = "inf"; break;
case FP_NAN: p = "nan"; break;
case FP_NORMAL: p = "normal"; break;
case FP_SUBNORMAL: p = "subnormal"; break;
case FP_ZERO: p = "zero"; break;
default: p = "bad fpclassify";
}
VTABLE_set_string_native(INTERP, retval,
Parrot_str_new_constant(INTERP, p));
RETURN(PMC *retval);
}
/*
=item C<PMC* frexp()>
=cut
*/
METHOD PMC* frexp() {
int _e;
const FLOATVAL _y = frexp(VTABLE_get_number(INTERP, SELF), &_e);
PMC * const y = Parrot_pmc_new(INTERP, dynpmc_LuaNumber);
PMC * const expn = Parrot_pmc_new(INTERP, dynpmc_LuaNumber);
PMC * const retval = Parrot_pmc_new(INTERP, enum_class_FixedPMCArray);
VTABLE_set_number_native(INTERP, y, _y);
VTABLE_set_integer_native(INTERP, expn, _e);
VTABLE_set_integer_native(INTERP, retval, 2);
VTABLE_set_pmc_keyed_int(INTERP, retval, 0, y);
VTABLE_set_pmc_keyed_int(INTERP, retval, 1, expn);
RETURN(PMC *retval);
}
/*
=item C<PMC* hypot(PMC* y)>
=cut
*/
METHOD PMC* hypot(PMC* y) {
const FLOATVAL n = hypot(VTABLE_get_number(INTERP, SELF),
VTABLE_get_number(INTERP, y));
PMC * const retval = Parrot_pmc_new(INTERP, dynpmc_LuaNumber);
VTABLE_set_number_native(INTERP, retval, n);
RETURN(PMC *retval);
}
/*
=item C<PMC* ilogb()>
=cut
*/
METHOD PMC* ilogb() {
const FLOATVAL n = ilogb(VTABLE_get_number(INTERP, SELF));
PMC * const retval = Parrot_pmc_new(INTERP, dynpmc_LuaNumber);
VTABLE_set_number_native(INTERP, retval, n);
RETURN(PMC *retval);
}
/*
=item C<PMC* isfinite()>
=cut
*/
METHOD PMC* isfinite() {
const INTVAL b = isfinite(VTABLE_get_number(INTERP, SELF));
PMC * const retval = Parrot_pmc_new(INTERP, dynpmc_LuaBoolean);
VTABLE_set_bool(INTERP, retval, b);
RETURN(PMC *retval);
}
/*
=item C<PMC* isinf()>
=cut
*/
METHOD PMC* isinf() {
const INTVAL b = isinf(VTABLE_get_number(INTERP, SELF));
PMC * const retval = Parrot_pmc_new(INTERP, dynpmc_LuaBoolean);
VTABLE_set_bool(INTERP, retval, b);
RETURN(PMC *retval);
}
/*
=item C<PMC* isnan()>
=cut
*/
METHOD PMC* isnan() {
const INTVAL b = isnan(VTABLE_get_number(INTERP, SELF));
PMC * const retval = Parrot_pmc_new(INTERP, dynpmc_LuaBoolean);
VTABLE_set_bool(INTERP, retval, b);
RETURN(PMC *retval);
}
/*
=item C<PMC* isnormal()>
=cut
*/
METHOD PMC* isnormal() {
const INTVAL b = isnormal(VTABLE_get_number(INTERP, SELF));
PMC * const retval = Parrot_pmc_new(INTERP, dynpmc_LuaBoolean);
VTABLE_set_bool(INTERP, retval, b);
RETURN(PMC *retval);
}
/*
=item C<PMC* ldexp(PMC *x, PMC *expn)>
=cut
*/
METHOD PMC* ldexp(PMC *expn) {
const FLOATVAL n = ldexp(VTABLE_get_number(INTERP, SELF),
VTABLE_get_integer(INTERP, expn));
PMC * const retval = Parrot_pmc_new(INTERP, dynpmc_LuaNumber);
VTABLE_set_number_native(INTERP, retval, n);
RETURN(PMC *retval);
}
/*
=item C<PMC* lgamma()>
=cut
*/
METHOD PMC* lgamma() {
const FLOATVAL n = lgamma(VTABLE_get_number(INTERP, SELF));
PMC * const retval = Parrot_pmc_new(INTERP, dynpmc_LuaNumber);
VTABLE_set_number_native(INTERP, retval, n);
RETURN(PMC *retval);
}
/*
=item C<PMC* log1p()>
=cut
*/
METHOD PMC* log1p() {
const FLOATVAL n = log1p(VTABLE_get_number(INTERP, SELF));
PMC * const retval = Parrot_pmc_new(INTERP, dynpmc_LuaNumber);
VTABLE_set_number_native(INTERP, retval, n);
RETURN(PMC *retval);
}
/*
=item C<PMC* log2()>
=cut
*/
METHOD PMC* log2() {
const FLOATVAL n = log2(VTABLE_get_number(INTERP, SELF));
PMC * const retval = Parrot_pmc_new(INTERP, dynpmc_LuaNumber);
VTABLE_set_number_native(INTERP, retval, n);
RETURN(PMC *retval);
}
/*
=item C<PMC* logb()>
=cut
*/
METHOD PMC* logb() {
const FLOATVAL n = logb(VTABLE_get_number(INTERP, SELF));
PMC * const retval = Parrot_pmc_new(INTERP, dynpmc_LuaNumber);
VTABLE_set_number_native(INTERP, retval, n);
RETURN(PMC *retval);
}
/*
=item C<PMC* modf()>
=cut
*/
METHOD PMC* modf() {
FLOATVAL _d;
const FLOATVAL _y = modf(VTABLE_get_number(INTERP, SELF), &_d);
PMC * const y = Parrot_pmc_new(INTERP, dynpmc_LuaNumber);
PMC * const d = Parrot_pmc_new(INTERP, dynpmc_LuaNumber);
PMC * const retval = Parrot_pmc_new(INTERP, enum_class_FixedPMCArray);
VTABLE_set_number_native(INTERP, y, _y);
VTABLE_set_number_native(INTERP, d, _d);
VTABLE_set_integer_native(INTERP, retval, 2);
VTABLE_set_pmc_keyed_int(INTERP, retval, 0, d);
VTABLE_set_pmc_keyed_int(INTERP, retval, 1, y);
RETURN(PMC *retval);
}
/*
=item C<PMC* nearbyint()>
=cut
*/
METHOD PMC* nearbyint() {
const FLOATVAL n = nearbyint(VTABLE_get_number(INTERP, SELF));
PMC * const retval = Parrot_pmc_new(INTERP, dynpmc_LuaNumber);
VTABLE_set_number_native(INTERP, retval, n);
RETURN(PMC *retval);
}
/*
=item C<PMC* nextafter(PMC* y)>
=cut
*/
METHOD PMC* nextafter(PMC* y) {
const FLOATVAL n = nextafter(VTABLE_get_number(INTERP, SELF),
VTABLE_get_number(INTERP, y));
PMC * const retval = Parrot_pmc_new(INTERP, dynpmc_LuaNumber);
VTABLE_set_number_native(INTERP, retval, n);
RETURN(PMC *retval);
}
/*
=item C<PMC* nexttoward(PMC* y)>
=cut
*/
METHOD PMC* nexttoward(PMC* y) {
const FLOATVAL n = nexttoward(VTABLE_get_number(INTERP, SELF),
VTABLE_get_number(INTERP, y));
PMC * const retval = Parrot_pmc_new(INTERP, dynpmc_LuaNumber);
VTABLE_set_number_native(INTERP, retval, n);
RETURN(PMC *retval);
}
/*
=item C<PMC *rawequal(PMC *value)>
=cut
*/
METHOD PMC *rawequal(PMC *value) {
const INTVAL b = (PMC_type(SELF) == PMC_type(value)
&& VTABLE_get_number(INTERP, SELF) == VTABLE_get_number(INTERP, value))
? 1 : 0;
PMC * const retval = Parrot_pmc_new(INTERP, dynpmc_LuaBoolean);
VTABLE_set_integer_native(INTERP, retval, b);
RETURN(PMC *retval);
}
/*
=item C<PMC* remainder(PMC* y)>
=cut
*/
METHOD PMC* remainder(PMC* y) {
const FLOATVAL n = remainder(VTABLE_get_number(INTERP, SELF),
VTABLE_get_number(INTERP, y));
PMC * const retval = Parrot_pmc_new(INTERP, dynpmc_LuaNumber);
VTABLE_set_number_native(INTERP, retval, n);
RETURN(PMC *retval);
}
/*
=item C<PMC* rint()>
=cut
*/
METHOD PMC* rint() {
const FLOATVAL n = rint(VTABLE_get_number(INTERP, SELF));
PMC * const retval = Parrot_pmc_new(INTERP, dynpmc_LuaNumber);
VTABLE_set_number_native(INTERP, retval, n);
RETURN(PMC *retval);
}
/*
=item C<PMC* round()>
=cut
*/
METHOD PMC* round() {
const FLOATVAL n = round(VTABLE_get_number(INTERP, SELF));
PMC * const retval = Parrot_pmc_new(INTERP, dynpmc_LuaNumber);
VTABLE_set_number_native(INTERP, retval, n);
RETURN(PMC *retval);
}
/*
=item C<PMC* scalbn(PMC* ex)>
=cut
*/
METHOD PMC* scalbn(PMC* ex) {
const FLOATVAL n = scalbn(VTABLE_get_number(INTERP, SELF),
VTABLE_get_number(INTERP, ex));
PMC * const retval = Parrot_pmc_new(INTERP, dynpmc_LuaNumber);
VTABLE_set_number_native(INTERP, retval, n);
RETURN(PMC *retval);
}
/*
=item C<PMC* signbit()>
=cut
*/
METHOD PMC* signbit() {
const FLOATVAL n = signbit(VTABLE_get_number(INTERP, SELF));
PMC * const retval = Parrot_pmc_new(INTERP, dynpmc_LuaNumber);
VTABLE_set_number_native(INTERP, retval, n);
RETURN(PMC *retval);
}
/*
=item C<PMC* sinh()>
=cut
*/
METHOD PMC* sinh() {
const FLOATVAL n = sinh(VTABLE_get_number(INTERP, SELF));
PMC * const retval = Parrot_pmc_new(INTERP, dynpmc_LuaNumber);
VTABLE_set_number_native(INTERP, retval, n);
RETURN(PMC *retval);
}
/*
=item C<PMC* tanh()>
=cut
*/
METHOD PMC* tanh() {
const FLOATVAL n = tanh(VTABLE_get_number(INTERP, SELF));
PMC * const retval = Parrot_pmc_new(INTERP, dynpmc_LuaNumber);
VTABLE_set_number_native(INTERP, retval, n);
RETURN(PMC *retval);
}
/*
=item C<PMC* tgamma()>
=cut
*/
METHOD PMC* tgamma() {
const FLOATVAL n = tgamma(VTABLE_get_number(INTERP, SELF));
PMC * const retval = Parrot_pmc_new(INTERP, dynpmc_LuaNumber);
VTABLE_set_number_native(INTERP, retval, n);
RETURN(PMC *retval);
}
/*
=item C<PMC* trunc()>
=cut
*/
METHOD PMC* trunc() {
const FLOATVAL n = trunc(VTABLE_get_number(INTERP, SELF));
PMC * const retval = Parrot_pmc_new(INTERP, dynpmc_LuaNumber);
VTABLE_set_number_native(INTERP, retval, n);
RETURN(PMC *retval);
}
/*
=item C<PMC *tonumber()>
=cut
*/
METHOD PMC *tonumber() {
PMC * const clone = SELF.clone();
RETURN(PMC *clone);
}
}
/*
=back
=cut
*/
/*
* Local variables:
* c-file-style: "parrot"
* End:
* vim: expandtab shiftwidth=4:
*/