/*
Copyright (C) 2008, The Perl Foundation.
$Id: /mirror/trunk/languages/pipp/src/pmc/phpfloat.pmc 35737 2009-01-17T19:09:05.140782Z bernhard  $

=head1 NAME

src/pmc/phpfloat.pmc - PHP Float

=head1 DESCRIPTION

=head2 Methods

=over 4

=cut

*/

#include "php_private.h"

pmclass PhpFloat
    extends  Float
    provides scalar
    provides float
    dynpmc
    group    php_group
    hll      PHP
    maps     Float {
    ATTR FLOATVAL fv;

/*

=item C<STRING* name()>

Return the string 'double'.

=cut

*/
    STRING* name() {
        return const_string(INTERP, "double");
    }

/*

=back

=head2 non-Vtable Methods

=over 4

=item C<STRING* serialize()>

Return a representation of this float in the same format as PHP's serialize function.

=cut

*/

    METHOD STRING* serialize() {
        STRING *serialized;
        INTVAL zero_index = -1;

        /* PHP's serialized floats stringify the exact value stored rather than
         * just the significant digits.  */
        serialized = string_printf(INTERP, "%.*f", 100, VTABLE_get_number(INTERP, SELF));
        while (string_ord(INTERP, serialized, zero_index - 1) == '0')
            zero_index--;

        serialized = string_chopn(INTERP, serialized, 0 - zero_index);
        serialized = string_printf(INTERP, "f:%Ss;", serialized);
        RETURN(STRING *serialized);
    }


/*

=back

=head2 Specific Methods

=over 4

=item C<PMC* acosh()>

=cut

*/
    METHOD acosh() {
        PMC * const d  = pmc_new(INTERP, VTABLE_type(INTERP, SELF));
        SET_ATTR_fv(INTERP, d, acosh(SELF.get_number()));
        RETURN(PMC *d);
    }

/*

=item C<PMC* asinh()>

=cut

*/
    METHOD asinh() {
        PMC * const d  = pmc_new(INTERP, VTABLE_type(INTERP, SELF));
        SET_ATTR_fv(INTERP, d, asinh(SELF.get_number()));
        RETURN(PMC *d);
    }

/*

=item C<PMC* atanh()>

=cut

*/
    METHOD atanh() {
        PMC * const d  = pmc_new(INTERP, VTABLE_type(INTERP, SELF));
        SET_ATTR_fv(INTERP, d, atanh(SELF.get_number()));
        RETURN(PMC *d);
    }

/*

=item C<PMC* is_finite()>

=cut

*/
    METHOD PMC* is_finite() {
        PMC *retval = pmc_new(INTERP, dynpmc_PhpBoolean);
#if 1
        FLOATVAL d = SELF.get_number();
        INTVAL val = finite(d);
        VTABLE_set_bool(INTERP, retval, val);
#else
        VTABLE_set_bool(INTERP, retval, 0);
#endif
        RETURN(PMC *retval);
    }

/*

=item C<PMC* is_infinite()>

=cut

*/
    METHOD PMC* is_infinite() {
        PMC *retval = pmc_new(INTERP, dynpmc_PhpBoolean);
#if 1
        FLOATVAL d = SELF.get_number();
        INTVAL val = isinf(d);
        VTABLE_set_bool(INTERP, retval, val);
#else
        VTABLE_set_bool(INTERP, retval, 0);
#endif
        RETURN(PMC *retval);
    }

/*

=item C<PMC* is_nan()>

=cut

*/
    METHOD PMC* is_nan() {
        PMC *retval = pmc_new(INTERP, dynpmc_PhpBoolean);
#if 1
        FLOATVAL d = SELF.get_number();
        INTVAL val = isnan(d);
        VTABLE_set_bool(INTERP, retval, val);
#else
        VTABLE_set_bool(INTERP, retval, 0);
#endif
        RETURN(PMC *retval);
    }

/*

=item C<PMC* to_number()>

=cut

*/
    METHOD PMC* to_number() {
        RETURN(PMC *SELF);
    }

}

/*

=back

=head1 AUTHORS

Francois Perrad.

=cut

*/


/*
 * Local variables:
 *   c-file-style: "parrot"
 * End:
 * vim: expandtab shiftwidth=4:
 */
