/* Generated automatically by jlpp - do not edit. */ #include static jakelib::lang::String* jakelib2_strings[] = {null, null, null}; // "null" static jchar chars_jakelib2_str_0[] = {110,117,108,108}; // "null" static jchar chars_jakelib2_str_1[] = {110,117,108,108}; // "" static jchar chars_jakelib2_str_2[] = {0}; #line 1 "lang/Float.jlc" // -*- c++ -*- /* * Jakelib2 - General purpose C++ library * Copyright (C) 2001 Florian Wolff (florian@donuz.de) * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2.1 of the License, or (at your option) any later version. * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * * $Id: Float.jlc,v 1.5 2003/09/27 08:10:28 florian Exp $ */ #include "jakelib2.h" #include "jakelib2/lang/Float.h" #include "jakelib2/lang/Double.h" #include "jakelib2/lang/Character.h" #include using namespace jakelib::lang; JAKELIB_IMPLEMENT_CLASS_1("jakelib.lang.Float", Float, Number, Comparable); // FIXME! //+++AlFa - these are from MS float.h (ANSI) //#define FLT_MAX 3.402823466e+38F /* max value */ //#define FLT_MIN 1.175494351e-38F /* min positive value */ const jfloat Float::MAX_VALUE = FLT_MAX; const jfloat Float::MIN_VALUE = FLT_MIN; /*****************************************************************************\ * Float | *****************************************************************************/ Float::Float(jfloat value) { this->value = value; } Float::Float(String* s) { value = parseFloat(s); } /*****************************************************************************\ * hashCode | *****************************************************************************/ jint Float::hashCode() { jlong v = (jlong) value; return (int) (v ^ (v >> 32)); } /*****************************************************************************\ * equals | *****************************************************************************/ jboolean Float::equals(Object* obj) { if (obj == null || !obj->getClass()->isInstance(this)) return false; Float* object = (Float*) obj; return ( value == object->value ); } /*****************************************************************************\ * toString | *****************************************************************************/ String* Float::toString() { return toString(value); } String* Float::toString(jfloat value) {/* if (value == 0) return new String("0"); char buf[30]; sprintf(buf, "%f", value); return new String(buf);*/ return Double::toString((jdouble) value); } /*****************************************************************************\ * parseInt | *****************************************************************************/ jfloat Float::parseFloat(String* str) { if (str == null) throw new NumberFormatException(JAKELIB_ONDEMAND(jakelib2_strings[0], new jakelib::lang::String(chars_jakelib2_str_0, 0, 4)) ->plus( JAKELIB_AT2("jakelib.lang.Float.parseFloat"))); char* ptr; jfloat v = (jfloat) strtod(str->latin1(), &ptr); if (*ptr != '\0') throw new NumberFormatException(str ->plus( JAKELIB_AT2("jakelib.lang.Float.parseFloat"))); return v; } jfloat Float::parseFloat(const char* str) { if (str == null) throw new NumberFormatException(JAKELIB_ONDEMAND(jakelib2_strings[1], new jakelib::lang::String(chars_jakelib2_str_1, 0, 4)) ->plus( JAKELIB_AT2("jakelib.lang.Float.parseFloat"))); char* ptr; jfloat v = (jfloat) strtod(str, &ptr); if (*ptr != '\0') throw new NumberFormatException(JAKELIB_ONDEMAND(jakelib2_strings[2], new jakelib::lang::String(chars_jakelib2_str_2, 0, 0)) ->plus( str )->plus( JAKELIB_AT2("jakelib.lang.Float.parseFloat"))); return v; } /*****************************************************************************\ * xxxValue | *****************************************************************************/ jbyte Float::byteValue() { return (jbyte) value; }; jfloat Float::floatValue() { return (jfloat) value; }; jint Float::intValue() { return (jint) value; }; jlong Float::longValue() { return (jlong) value; }; jdouble Float::doubleValue() { return (jdouble) value; }; jshort Float::shortValue() { return (jshort) value;} ; /*****************************************************************************\ * valueOf | *****************************************************************************/ Float* Float::valueOf(String* str) { return new Float(parseFloat(str)); } /*****************************************************************************\ * compareTo | *****************************************************************************/ int Float::compareTo(Float* obj) { jfloat otherValue = obj->value; return (value < otherValue ? -1 : (value > otherValue ? 1 : 0)); } int Float::compareTo(Object* obj) { return compareTo((Float*) obj); }