зеркало из https://github.com/mono/ikvm-fork.git
Imported Sun's GPLed Double/Float toString and parsing code to fix the long standing incompatibilities. Update license and copyright texts to note the inclusion of Sun code.
Note that FloatingDecimal has a couple of IKVM specific changes to work around a bug in the x64 CLR JIT. These changes are marked with /*IKVM*/
This commit is contained in:
Родитель
f933941c9f
Коммит
66bee2b0ba
364
LICENSE
364
LICENSE
|
@ -1,16 +1,24 @@
|
|||
IMPORTANT NOTICE
|
||||
|
||||
Some files in this distribution are part of GNU Classpath and have a
|
||||
different license. This applies in particular to:
|
||||
Copyright (C) 1998-2007 Free Software Foundation, Inc.
|
||||
Copyright (C) 1996-2007 Sun Microsystems, Inc.
|
||||
Copyright (C) 2002-2007 Jeroen Frijters
|
||||
|
||||
Some files in this distribution are part of GNU Classpath or OpenJDK and
|
||||
are licensed under the GNU General Public License (GPL) version 2
|
||||
with "Classpath" exception. This applies in particular to:
|
||||
- IKVM.GNU.Classpath.dll
|
||||
- some of the *.java files (see each file header for license)
|
||||
|
||||
See http://www.gnu.org/software/classpath/ for information on the
|
||||
GNU Classpath license.
|
||||
GNU Classpath license and "Classpath" exception.
|
||||
|
||||
See below for a full copy of the GPL license and the Sun version of the
|
||||
"Classpath" exception.
|
||||
|
||||
-----------------------------------------------------------------------------
|
||||
|
||||
Copyright (C) 2002, 2003, 2004, 2005 Jeroen Frijters
|
||||
Copyright (C) 2002-2007 Jeroen Frijters
|
||||
|
||||
This software is provided 'as-is', without any express or implied
|
||||
warranty. In no event will the authors be held liable for any damages
|
||||
|
@ -32,3 +40,351 @@ IMPORTANT NOTICE
|
|||
jeroen@frijters.net
|
||||
|
||||
-----------------------------------------------------------------------------
|
||||
|
||||
The GNU General Public License (GPL)
|
||||
|
||||
Version 2, June 1991
|
||||
|
||||
Copyright (C) 1989, 1991 Free Software Foundation, Inc.
|
||||
59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
|
||||
Everyone is permitted to copy and distribute verbatim copies of this license
|
||||
document, but changing it is not allowed.
|
||||
|
||||
Preamble
|
||||
|
||||
The licenses for most software are designed to take away your freedom to share
|
||||
and change it. By contrast, the GNU General Public License is intended to
|
||||
guarantee your freedom to share and change free software--to make sure the
|
||||
software is free for all its users. This General Public License applies to
|
||||
most of the Free Software Foundation's software and to any other program whose
|
||||
authors commit to using it. (Some other Free Software Foundation software is
|
||||
covered by the GNU Library General Public License instead.) You can apply it to
|
||||
your programs, too.
|
||||
|
||||
When we speak of free software, we are referring to freedom, not price. Our
|
||||
General Public Licenses are designed to make sure that you have the freedom to
|
||||
distribute copies of free software (and charge for this service if you wish),
|
||||
that you receive source code or can get it if you want it, that you can change
|
||||
the software or use pieces of it in new free programs; and that you know you
|
||||
can do these things.
|
||||
|
||||
To protect your rights, we need to make restrictions that forbid anyone to deny
|
||||
you these rights or to ask you to surrender the rights. These restrictions
|
||||
translate to certain responsibilities for you if you distribute copies of the
|
||||
software, or if you modify it.
|
||||
|
||||
For example, if you distribute copies of such a program, whether gratis or for
|
||||
a fee, you must give the recipients all the rights that you have. You must
|
||||
make sure that they, too, receive or can get the source code. And you must
|
||||
show them these terms so they know their rights.
|
||||
|
||||
We protect your rights with two steps: (1) copyright the software, and (2)
|
||||
offer you this license which gives you legal permission to copy, distribute
|
||||
and/or modify the software.
|
||||
|
||||
Also, for each author's protection and ours, we want to make certain that
|
||||
everyone understands that there is no warranty for this free software. If the
|
||||
software is modified by someone else and passed on, we want its recipients to
|
||||
know that what they have is not the original, so that any problems introduced
|
||||
by others will not reflect on the original authors' reputations.
|
||||
|
||||
Finally, any free program is threatened constantly by software patents. We
|
||||
wish to avoid the danger that redistributors of a free program will
|
||||
individually obtain patent licenses, in effect making the program proprietary.
|
||||
To prevent this, we have made it clear that any patent must be licensed for
|
||||
everyone's free use or not licensed at all.
|
||||
|
||||
The precise terms and conditions for copying, distribution and modification
|
||||
follow.
|
||||
|
||||
TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
|
||||
|
||||
0. This License applies to any program or other work which contains a notice
|
||||
placed by the copyright holder saying it may be distributed under the terms of
|
||||
this General Public License. The "Program", below, refers to any such program
|
||||
or work, and a "work based on the Program" means either the Program or any
|
||||
derivative work under copyright law: that is to say, a work containing the
|
||||
Program or a portion of it, either verbatim or with modifications and/or
|
||||
translated into another language. (Hereinafter, translation is included
|
||||
without limitation in the term "modification".) Each licensee is addressed as
|
||||
"you".
|
||||
|
||||
Activities other than copying, distribution and modification are not covered by
|
||||
this License; they are outside its scope. The act of running the Program is
|
||||
not restricted, and the output from the Program is covered only if its contents
|
||||
constitute a work based on the Program (independent of having been made by
|
||||
running the Program). Whether that is true depends on what the Program does.
|
||||
|
||||
1. You may copy and distribute verbatim copies of the Program's source code as
|
||||
you receive it, in any medium, provided that you conspicuously and
|
||||
appropriately publish on each copy an appropriate copyright notice and
|
||||
disclaimer of warranty; keep intact all the notices that refer to this License
|
||||
and to the absence of any warranty; and give any other recipients of the
|
||||
Program a copy of this License along with the Program.
|
||||
|
||||
You may charge a fee for the physical act of transferring a copy, and you may
|
||||
at your option offer warranty protection in exchange for a fee.
|
||||
|
||||
2. You may modify your copy or copies of the Program or any portion of it, thus
|
||||
forming a work based on the Program, and copy and distribute such modifications
|
||||
or work under the terms of Section 1 above, provided that you also meet all of
|
||||
these conditions:
|
||||
|
||||
a) You must cause the modified files to carry prominent notices stating
|
||||
that you changed the files and the date of any change.
|
||||
|
||||
b) You must cause any work that you distribute or publish, that in whole or
|
||||
in part contains or is derived from the Program or any part thereof, to be
|
||||
licensed as a whole at no charge to all third parties under the terms of
|
||||
this License.
|
||||
|
||||
c) If the modified program normally reads commands interactively when run,
|
||||
you must cause it, when started running for such interactive use in the
|
||||
most ordinary way, to print or display an announcement including an
|
||||
appropriate copyright notice and a notice that there is no warranty (or
|
||||
else, saying that you provide a warranty) and that users may redistribute
|
||||
the program under these conditions, and telling the user how to view a copy
|
||||
of this License. (Exception: if the Program itself is interactive but does
|
||||
not normally print such an announcement, your work based on the Program is
|
||||
not required to print an announcement.)
|
||||
|
||||
These requirements apply to the modified work as a whole. If identifiable
|
||||
sections of that work are not derived from the Program, and can be reasonably
|
||||
considered independent and separate works in themselves, then this License, and
|
||||
its terms, do not apply to those sections when you distribute them as separate
|
||||
works. But when you distribute the same sections as part of a whole which is a
|
||||
work based on the Program, the distribution of the whole must be on the terms
|
||||
of this License, whose permissions for other licensees extend to the entire
|
||||
whole, and thus to each and every part regardless of who wrote it.
|
||||
|
||||
Thus, it is not the intent of this section to claim rights or contest your
|
||||
rights to work written entirely by you; rather, the intent is to exercise the
|
||||
right to control the distribution of derivative or collective works based on
|
||||
the Program.
|
||||
|
||||
In addition, mere aggregation of another work not based on the Program with the
|
||||
Program (or with a work based on the Program) on a volume of a storage or
|
||||
distribution medium does not bring the other work under the scope of this
|
||||
License.
|
||||
|
||||
3. You may copy and distribute the Program (or a work based on it, under
|
||||
Section 2) in object code or executable form under the terms of Sections 1 and
|
||||
2 above provided that you also do one of the following:
|
||||
|
||||
a) Accompany it with the complete corresponding machine-readable source
|
||||
code, which must be distributed under the terms of Sections 1 and 2 above
|
||||
on a medium customarily used for software interchange; or,
|
||||
|
||||
b) Accompany it with a written offer, valid for at least three years, to
|
||||
give any third party, for a charge no more than your cost of physically
|
||||
performing source distribution, a complete machine-readable copy of the
|
||||
corresponding source code, to be distributed under the terms of Sections 1
|
||||
and 2 above on a medium customarily used for software interchange; or,
|
||||
|
||||
c) Accompany it with the information you received as to the offer to
|
||||
distribute corresponding source code. (This alternative is allowed only
|
||||
for noncommercial distribution and only if you received the program in
|
||||
object code or executable form with such an offer, in accord with
|
||||
Subsection b above.)
|
||||
|
||||
The source code for a work means the preferred form of the work for making
|
||||
modifications to it. For an executable work, complete source code means all
|
||||
the source code for all modules it contains, plus any associated interface
|
||||
definition files, plus the scripts used to control compilation and installation
|
||||
of the executable. However, as a special exception, the source code
|
||||
distributed need not include anything that is normally distributed (in either
|
||||
source or binary form) with the major components (compiler, kernel, and so on)
|
||||
of the operating system on which the executable runs, unless that component
|
||||
itself accompanies the executable.
|
||||
|
||||
If distribution of executable or object code is made by offering access to copy
|
||||
from a designated place, then offering equivalent access to copy the source
|
||||
code from the same place counts as distribution of the source code, even though
|
||||
third parties are not compelled to copy the source along with the object code.
|
||||
|
||||
4. You may not copy, modify, sublicense, or distribute the Program except as
|
||||
expressly provided under this License. Any attempt otherwise to copy, modify,
|
||||
sublicense or distribute the Program is void, and will automatically terminate
|
||||
your rights under this License. However, parties who have received copies, or
|
||||
rights, from you under this License will not have their licenses terminated so
|
||||
long as such parties remain in full compliance.
|
||||
|
||||
5. You are not required to accept this License, since you have not signed it.
|
||||
However, nothing else grants you permission to modify or distribute the Program
|
||||
or its derivative works. These actions are prohibited by law if you do not
|
||||
accept this License. Therefore, by modifying or distributing the Program (or
|
||||
any work based on the Program), you indicate your acceptance of this License to
|
||||
do so, and all its terms and conditions for copying, distributing or modifying
|
||||
the Program or works based on it.
|
||||
|
||||
6. Each time you redistribute the Program (or any work based on the Program),
|
||||
the recipient automatically receives a license from the original licensor to
|
||||
copy, distribute or modify the Program subject to these terms and conditions.
|
||||
You may not impose any further restrictions on the recipients' exercise of the
|
||||
rights granted herein. You are not responsible for enforcing compliance by
|
||||
third parties to this License.
|
||||
|
||||
7. If, as a consequence of a court judgment or allegation of patent
|
||||
infringement or for any other reason (not limited to patent issues), conditions
|
||||
are imposed on you (whether by court order, agreement or otherwise) that
|
||||
contradict the conditions of this License, they do not excuse you from the
|
||||
conditions of this License. If you cannot distribute so as to satisfy
|
||||
simultaneously your obligations under this License and any other pertinent
|
||||
obligations, then as a consequence you may not distribute the Program at all.
|
||||
For example, if a patent license would not permit royalty-free redistribution
|
||||
of the Program by all those who receive copies directly or indirectly through
|
||||
you, then the only way you could satisfy both it and this License would be to
|
||||
refrain entirely from distribution of the Program.
|
||||
|
||||
If any portion of this section is held invalid or unenforceable under any
|
||||
particular circumstance, the balance of the section is intended to apply and
|
||||
the section as a whole is intended to apply in other circumstances.
|
||||
|
||||
It is not the purpose of this section to induce you to infringe any patents or
|
||||
other property right claims or to contest validity of any such claims; this
|
||||
section has the sole purpose of protecting the integrity of the free software
|
||||
distribution system, which is implemented by public license practices. Many
|
||||
people have made generous contributions to the wide range of software
|
||||
distributed through that system in reliance on consistent application of that
|
||||
system; it is up to the author/donor to decide if he or she is willing to
|
||||
distribute software through any other system and a licensee cannot impose that
|
||||
choice.
|
||||
|
||||
This section is intended to make thoroughly clear what is believed to be a
|
||||
consequence of the rest of this License.
|
||||
|
||||
8. If the distribution and/or use of the Program is restricted in certain
|
||||
countries either by patents or by copyrighted interfaces, the original
|
||||
copyright holder who places the Program under this License may add an explicit
|
||||
geographical distribution limitation excluding those countries, so that
|
||||
distribution is permitted only in or among countries not thus excluded. In
|
||||
such case, this License incorporates the limitation as if written in the body
|
||||
of this License.
|
||||
|
||||
9. The Free Software Foundation may publish revised and/or new versions of the
|
||||
General Public License from time to time. Such new versions will be similar in
|
||||
spirit to the present version, but may differ in detail to address new problems
|
||||
or concerns.
|
||||
|
||||
Each version is given a distinguishing version number. If the Program
|
||||
specifies a version number of this License which applies to it and "any later
|
||||
version", you have the option of following the terms and conditions either of
|
||||
that version or of any later version published by the Free Software Foundation.
|
||||
If the Program does not specify a version number of this License, you may
|
||||
choose any version ever published by the Free Software Foundation.
|
||||
|
||||
10. If you wish to incorporate parts of the Program into other free programs
|
||||
whose distribution conditions are different, write to the author to ask for
|
||||
permission. For software which is copyrighted by the Free Software Foundation,
|
||||
write to the Free Software Foundation; we sometimes make exceptions for this.
|
||||
Our decision will be guided by the two goals of preserving the free status of
|
||||
all derivatives of our free software and of promoting the sharing and reuse of
|
||||
software generally.
|
||||
|
||||
NO WARRANTY
|
||||
|
||||
11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY FOR
|
||||
THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN OTHERWISE
|
||||
STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES PROVIDE THE
|
||||
PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED,
|
||||
INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
|
||||
FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND
|
||||
PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE,
|
||||
YOU ASSUME THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION.
|
||||
|
||||
12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING WILL
|
||||
ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR REDISTRIBUTE THE
|
||||
PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY
|
||||
GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR
|
||||
INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA
|
||||
BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A
|
||||
FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), EVEN IF SUCH HOLDER
|
||||
OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
|
||||
|
||||
END OF TERMS AND CONDITIONS
|
||||
|
||||
How to Apply These Terms to Your New Programs
|
||||
|
||||
If you develop a new program, and you want it to be of the greatest possible
|
||||
use to the public, the best way to achieve this is to make it free software
|
||||
which everyone can redistribute and change under these terms.
|
||||
|
||||
To do so, attach the following notices to the program. It is safest to attach
|
||||
them to the start of each source file to most effectively convey the exclusion
|
||||
of warranty; and each file should have at least the "copyright" line and a
|
||||
pointer to where the full notice is found.
|
||||
|
||||
One line to give the program's name and a brief idea of what it does.
|
||||
|
||||
Copyright (C) <year> <name of author>
|
||||
|
||||
This program is free software; you can redistribute it and/or modify it
|
||||
under the terms of the GNU General Public License as published by the Free
|
||||
Software Foundation; either version 2 of the License, or (at your option)
|
||||
any later version.
|
||||
|
||||
This program 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 General Public License for
|
||||
more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License along
|
||||
with this program; if not, write to the Free Software Foundation, Inc., 59
|
||||
Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
|
||||
Also add information on how to contact you by electronic and paper mail.
|
||||
|
||||
If the program is interactive, make it output a short notice like this when it
|
||||
starts in an interactive mode:
|
||||
|
||||
Gnomovision version 69, Copyright (C) year name of author Gnomovision comes
|
||||
with ABSOLUTELY NO WARRANTY; for details type 'show w'. This is free
|
||||
software, and you are welcome to redistribute it under certain conditions;
|
||||
type 'show c' for details.
|
||||
|
||||
The hypothetical commands 'show w' and 'show c' should show the appropriate
|
||||
parts of the General Public License. Of course, the commands you use may be
|
||||
called something other than 'show w' and 'show c'; they could even be
|
||||
mouse-clicks or menu items--whatever suits your program.
|
||||
|
||||
You should also get your employer (if you work as a programmer) or your school,
|
||||
if any, to sign a "copyright disclaimer" for the program, if necessary. Here
|
||||
is a sample; alter the names:
|
||||
|
||||
Yoyodyne, Inc., hereby disclaims all copyright interest in the program
|
||||
'Gnomovision' (which makes passes at compilers) written by James Hacker.
|
||||
|
||||
signature of Ty Coon, 1 April 1989
|
||||
|
||||
Ty Coon, President of Vice
|
||||
|
||||
This General Public License does not permit incorporating your program into
|
||||
proprietary programs. If your program is a subroutine library, you may
|
||||
consider it more useful to permit linking proprietary applications with the
|
||||
library. If this is what you want to do, use the GNU Library General Public
|
||||
License instead of this License.
|
||||
|
||||
|
||||
"CLASSPATH" EXCEPTION TO THE GPL
|
||||
|
||||
Certain source files distributed by Sun Microsystems, Inc. are subject to
|
||||
the following clarification and special exception to the GPL, but only where
|
||||
Sun has expressly included in the particular source file's header the words
|
||||
"Sun designates this particular file as subject to the "Classpath" exception
|
||||
as provided by Sun in the LICENSE file that accompanied this code."
|
||||
|
||||
Linking this library statically or dynamically with other modules is making
|
||||
a combined work based on this library. Thus, the terms and conditions of
|
||||
the GNU General Public License cover the whole combination.
|
||||
|
||||
As a special exception, the copyright holders of this library give you
|
||||
permission to link this library with independent modules to produce an
|
||||
executable, regardless of the license terms of these independent modules,
|
||||
and to copy and distribute the resulting executable under terms of your
|
||||
choice, provided that you also meet, for each linked independent module,
|
||||
the terms and conditions of the license of that module. An independent
|
||||
module is a module which is not derived from or based on this library. If
|
||||
you modify this library, you may extend this exception to your version of
|
||||
the library, but you are not obligated to do so. If you do not wish to do
|
||||
so, delete this exception statement from your version.
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
Copyright (C) 2006 Jeroen Frijters
|
||||
Copyright (C) 2006, 2007 Jeroen Frijters
|
||||
|
||||
This software is provided 'as-is', without any express or implied
|
||||
warranty. In no event will the authors be held liable for any damages
|
||||
|
@ -23,9 +23,10 @@
|
|||
*/
|
||||
|
||||
@cli.System.Reflection.AssemblyCopyrightAttribute.Annotation(
|
||||
"This software is licensed under the GNU General Public License + GNU Classpath exception.\r\n" +
|
||||
"This software is licensed under the GNU General Public License version 2 + \"Classpath\" exception.\r\n" +
|
||||
"See http://www.gnu.org/software/classpath/license.html for details.\r\n" +
|
||||
"Copyright (C) 1998-2007 Free Software Foundation, Inc.\r\n" +
|
||||
"Copyright (C) 1996-2007 Sun Microsystems, Inc.\r\n" +
|
||||
"Copyright (C) 2002-2007 Jeroen Frijters"
|
||||
)
|
||||
|
||||
|
|
|
@ -5002,7 +5002,6 @@ ikvm/runtime/Startup.java
|
|||
ikvm/runtime/Util.java
|
||||
java/io/VMFile.java
|
||||
java/io/VMObjectInputStream.java
|
||||
java/lang/DoubleToString.java
|
||||
java/lang/ExceptionHelper.java
|
||||
java/lang/LibraryVMInterfaceImpl.java
|
||||
java/lang/management/VMManagementFactory.java
|
||||
|
@ -5041,6 +5040,10 @@ java/util/concurrent/atomic/AtomicReference.java
|
|||
java/util/concurrent/atomic/AtomicReferenceArray.java
|
||||
java/util/concurrent/locks/LockSupport.java
|
||||
java/util/VMTimeZone.java
|
||||
sun/misc/DoubleConsts.java
|
||||
sun/misc/FloatConsts.java
|
||||
sun/misc/FloatingDecimal.java
|
||||
sun/misc/FpUtils.java
|
||||
sun/misc/Ref.java
|
||||
sun/misc/Unsafe.java
|
||||
sun/reflect/Reflection.java
|
||||
|
|
|
@ -1,663 +0,0 @@
|
|||
// NOTE this code was adapted from source code accompanying the article
|
||||
// http://www.onjava.com/pub/a/onjava/2000/12/15/formatting_doubles.html?page=2
|
||||
// by Jack Shirazi
|
||||
|
||||
package java.lang;
|
||||
|
||||
class DoubleToString
|
||||
{
|
||||
//Hardcode some byte arrays to make them quickly available
|
||||
public static final char[] INFINITY = {'I','n','f','i','n','i','t','y'};
|
||||
public static final char[] NaN = {'N','a','N'};
|
||||
public static final char[][] ZEROS = {
|
||||
{},
|
||||
{'0'},
|
||||
{'0','0'},
|
||||
{'0','0','0'},
|
||||
{'0','0','0','0'},
|
||||
{'0','0','0','0','0'},
|
||||
{'0','0','0','0','0','0'},
|
||||
{'0','0','0','0','0','0','0'},
|
||||
{'0','0','0','0','0','0','0','0'},
|
||||
{'0','0','0','0','0','0','0','0','0'},
|
||||
{'0','0','0','0','0','0','0','0','0','0'},
|
||||
{'0','0','0','0','0','0','0','0','0','0','0'},
|
||||
{'0','0','0','0','0','0','0','0','0','0','0','0'},
|
||||
{'0','0','0','0','0','0','0','0','0','0','0','0','0'},
|
||||
{'0','0','0','0','0','0','0','0','0','0','0','0','0','0'},
|
||||
{'0','0','0','0','0','0','0','0','0','0','0','0','0','0','0'},
|
||||
{'0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0'},
|
||||
{'0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0'},
|
||||
{'0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0'},
|
||||
{'0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0'},
|
||||
{'0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0'},
|
||||
};
|
||||
|
||||
private static final char[] charForDigit = {
|
||||
'0','1','2','3','4','5','6','7','8','9','a','b','c','d','e','f','g','h',
|
||||
'i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z'
|
||||
};
|
||||
|
||||
//And required double related constants.
|
||||
private static final long DoubleSignMask = 0x8000000000000000L;
|
||||
private static final long DoubleExpMask = 0x7ff0000000000000L;
|
||||
private static final long DoubleFractMask= ~(DoubleSignMask|DoubleExpMask);
|
||||
private static final int DoubleExpShift = 52;
|
||||
private static final int DoubleExpBias = 1023;
|
||||
|
||||
private static final double[] d_tenthPowers = {
|
||||
1e-323D, 1e-322D, 1e-321D, 1e-320D, 1e-319D, 1e-318D, 1e-317D, 1e-316D, 1e-315D, 1e-314D,
|
||||
1e-313D, 1e-312D, 1e-311D, 1e-310D, 1e-309D, 1e-308D, 1e-307D, 1e-306D, 1e-305D, 1e-304D,
|
||||
1e-303D, 1e-302D, 1e-301D, 1e-300D, 1e-299D, 1e-298D, 1e-297D, 1e-296D, 1e-295D, 1e-294D,
|
||||
1e-293D, 1e-292D, 1e-291D, 1e-290D, 1e-289D, 1e-288D, 1e-287D, 1e-286D, 1e-285D, 1e-284D,
|
||||
1e-283D, 1e-282D, 1e-281D, 1e-280D, 1e-279D, 1e-278D, 1e-277D, 1e-276D, 1e-275D, 1e-274D,
|
||||
1e-273D, 1e-272D, 1e-271D, 1e-270D, 1e-269D, 1e-268D, 1e-267D, 1e-266D, 1e-265D, 1e-264D,
|
||||
1e-263D, 1e-262D, 1e-261D, 1e-260D, 1e-259D, 1e-258D, 1e-257D, 1e-256D, 1e-255D, 1e-254D,
|
||||
1e-253D, 1e-252D, 1e-251D, 1e-250D, 1e-249D, 1e-248D, 1e-247D, 1e-246D, 1e-245D, 1e-244D,
|
||||
1e-243D, 1e-242D, 1e-241D, 1e-240D, 1e-239D, 1e-238D, 1e-237D, 1e-236D, 1e-235D, 1e-234D,
|
||||
1e-233D, 1e-232D, 1e-231D, 1e-230D, 1e-229D, 1e-228D, 1e-227D, 1e-226D, 1e-225D, 1e-224D,
|
||||
1e-223D, 1e-222D, 1e-221D, 1e-220D, 1e-219D, 1e-218D, 1e-217D, 1e-216D, 1e-215D, 1e-214D,
|
||||
1e-213D, 1e-212D, 1e-211D, 1e-210D, 1e-209D, 1e-208D, 1e-207D, 1e-206D, 1e-205D, 1e-204D,
|
||||
1e-203D, 1e-202D, 1e-201D, 1e-200D, 1e-199D, 1e-198D, 1e-197D, 1e-196D, 1e-195D, 1e-194D,
|
||||
1e-193D, 1e-192D, 1e-191D, 1e-190D, 1e-189D, 1e-188D, 1e-187D, 1e-186D, 1e-185D, 1e-184D,
|
||||
1e-183D, 1e-182D, 1e-181D, 1e-180D, 1e-179D, 1e-178D, 1e-177D, 1e-176D, 1e-175D, 1e-174D,
|
||||
1e-173D, 1e-172D, 1e-171D, 1e-170D, 1e-169D, 1e-168D, 1e-167D, 1e-166D, 1e-165D, 1e-164D,
|
||||
1e-163D, 1e-162D, 1e-161D, 1e-160D, 1e-159D, 1e-158D, 1e-157D, 1e-156D, 1e-155D, 1e-154D,
|
||||
1e-153D, 1e-152D, 1e-151D, 1e-150D, 1e-149D, 1e-148D, 1e-147D, 1e-146D, 1e-145D, 1e-144D,
|
||||
1e-143D, 1e-142D, 1e-141D, 1e-140D, 1e-139D, 1e-138D, 1e-137D, 1e-136D, 1e-135D, 1e-134D,
|
||||
1e-133D, 1e-132D, 1e-131D, 1e-130D, 1e-129D, 1e-128D, 1e-127D, 1e-126D, 1e-125D, 1e-124D,
|
||||
1e-123D, 1e-122D, 1e-121D, 1e-120D, 1e-119D, 1e-118D, 1e-117D, 1e-116D, 1e-115D, 1e-114D,
|
||||
1e-113D, 1e-112D, 1e-111D, 1e-110D, 1e-109D, 1e-108D, 1e-107D, 1e-106D, 1e-105D, 1e-104D,
|
||||
1e-103D, 1e-102D, 1e-101D, 1e-100D, 1e-99D, 1e-98D, 1e-97D, 1e-96D, 1e-95D, 1e-94D,
|
||||
1e-93D, 1e-92D, 1e-91D, 1e-90D, 1e-89D, 1e-88D, 1e-87D, 1e-86D, 1e-85D, 1e-84D,
|
||||
1e-83D, 1e-82D, 1e-81D, 1e-80D, 1e-79D, 1e-78D, 1e-77D, 1e-76D, 1e-75D, 1e-74D,
|
||||
1e-73D, 1e-72D, 1e-71D, 1e-70D, 1e-69D, 1e-68D, 1e-67D, 1e-66D, 1e-65D, 1e-64D,
|
||||
1e-63D, 1e-62D, 1e-61D, 1e-60D, 1e-59D, 1e-58D, 1e-57D, 1e-56D, 1e-55D, 1e-54D,
|
||||
1e-53D, 1e-52D, 1e-51D, 1e-50D, 1e-49D, 1e-48D, 1e-47D, 1e-46D, 1e-45D, 1e-44D,
|
||||
1e-43D, 1e-42D, 1e-41D, 1e-40D, 1e-39D, 1e-38D, 1e-37D, 1e-36D, 1e-35D, 1e-34D,
|
||||
1e-33D, 1e-32D, 1e-31D, 1e-30D, 1e-29D, 1e-28D, 1e-27D, 1e-26D, 1e-25D, 1e-24D,
|
||||
1e-23D, 1e-22D, 1e-21D, 1e-20D, 1e-19D, 1e-18D, 1e-17D, 1e-16D, 1e-15D, 1e-14D,
|
||||
1e-13D, 1e-12D, 1e-11D, 1e-10D, 1e-9D, 1e-8D, 1e-7D, 1e-6D, 1e-5D, 1e-4D,
|
||||
1e-3D, 1e-2D, 1e-1D, 1e0D, 1e1D, 1e2D, 1e3D, 1e4D,
|
||||
1e5D, 1e6D, 1e7D, 1e8D, 1e9D, 1e10D, 1e11D, 1e12D, 1e13D, 1e14D,
|
||||
1e15D, 1e16D, 1e17D, 1e18D, 1e19D, 1e20D, 1e21D, 1e22D, 1e23D, 1e24D,
|
||||
1e25D, 1e26D, 1e27D, 1e28D, 1e29D, 1e30D, 1e31D, 1e32D, 1e33D, 1e34D,
|
||||
1e35D, 1e36D, 1e37D, 1e38D, 1e39D, 1e40D, 1e41D, 1e42D, 1e43D, 1e44D,
|
||||
1e45D, 1e46D, 1e47D, 1e48D, 1e49D, 1e50D, 1e51D, 1e52D, 1e53D, 1e54D,
|
||||
1e55D, 1e56D, 1e57D, 1e58D, 1e59D, 1e60D, 1e61D, 1e62D, 1e63D, 1e64D,
|
||||
1e65D, 1e66D, 1e67D, 1e68D, 1e69D, 1e70D, 1e71D, 1e72D, 1e73D, 1e74D,
|
||||
1e75D, 1e76D, 1e77D, 1e78D, 1e79D, 1e80D, 1e81D, 1e82D, 1e83D, 1e84D,
|
||||
1e85D, 1e86D, 1e87D, 1e88D, 1e89D, 1e90D, 1e91D, 1e92D, 1e93D, 1e94D,
|
||||
1e95D, 1e96D, 1e97D, 1e98D, 1e99D, 1e100D, 1e101D, 1e102D, 1e103D, 1e104D,
|
||||
1e105D, 1e106D, 1e107D, 1e108D, 1e109D, 1e110D, 1e111D, 1e112D, 1e113D, 1e114D,
|
||||
1e115D, 1e116D, 1e117D, 1e118D, 1e119D, 1e120D, 1e121D, 1e122D, 1e123D, 1e124D,
|
||||
1e125D, 1e126D, 1e127D, 1e128D, 1e129D, 1e130D, 1e131D, 1e132D, 1e133D, 1e134D,
|
||||
1e135D, 1e136D, 1e137D, 1e138D, 1e139D, 1e140D, 1e141D, 1e142D, 1e143D, 1e144D,
|
||||
1e145D, 1e146D, 1e147D, 1e148D, 1e149D, 1e150D, 1e151D, 1e152D, 1e153D, 1e154D,
|
||||
1e155D, 1e156D, 1e157D, 1e158D, 1e159D, 1e160D, 1e161D, 1e162D, 1e163D, 1e164D,
|
||||
1e165D, 1e166D, 1e167D, 1e168D, 1e169D, 1e170D, 1e171D, 1e172D, 1e173D, 1e174D,
|
||||
1e175D, 1e176D, 1e177D, 1e178D, 1e179D, 1e180D, 1e181D, 1e182D, 1e183D, 1e184D,
|
||||
1e185D, 1e186D, 1e187D, 1e188D, 1e189D, 1e190D, 1e191D, 1e192D, 1e193D, 1e194D,
|
||||
1e195D, 1e196D, 1e197D, 1e198D, 1e199D, 1e200D, 1e201D, 1e202D, 1e203D, 1e204D,
|
||||
1e205D, 1e206D, 1e207D, 1e208D, 1e209D, 1e210D, 1e211D, 1e212D, 1e213D, 1e214D,
|
||||
1e215D, 1e216D, 1e217D, 1e218D, 1e219D, 1e220D, 1e221D, 1e222D, 1e223D, 1e224D,
|
||||
1e225D, 1e226D, 1e227D, 1e228D, 1e229D, 1e230D, 1e231D, 1e232D, 1e233D, 1e234D,
|
||||
1e235D, 1e236D, 1e237D, 1e238D, 1e239D, 1e240D, 1e241D, 1e242D, 1e243D, 1e244D,
|
||||
1e245D, 1e246D, 1e247D, 1e248D, 1e249D, 1e250D, 1e251D, 1e252D, 1e253D, 1e254D,
|
||||
1e255D, 1e256D, 1e257D, 1e258D, 1e259D, 1e260D, 1e261D, 1e262D, 1e263D, 1e264D,
|
||||
1e265D, 1e266D, 1e267D, 1e268D, 1e269D, 1e270D, 1e271D, 1e272D, 1e273D, 1e274D,
|
||||
1e275D, 1e276D, 1e277D, 1e278D, 1e279D, 1e280D, 1e281D, 1e282D, 1e283D, 1e284D,
|
||||
1e285D, 1e286D, 1e287D, 1e288D, 1e289D, 1e290D, 1e291D, 1e292D, 1e293D, 1e294D,
|
||||
1e295D, 1e296D, 1e297D, 1e298D, 1e299D, 1e300D, 1e301D, 1e302D, 1e303D, 1e304D,
|
||||
1e305D, 1e306D, 1e307D, 1e308D
|
||||
};
|
||||
|
||||
|
||||
public void appendFormatted(StringBuffer s, double d, int numFractDigits,
|
||||
char decimalPoint, char thousandsSeparator, int numDigitsSeparated,
|
||||
char negativePrefix, char negativeSuffix)
|
||||
{
|
||||
//First check for the special cases, +/-infinity, Not-a-number and -0.0
|
||||
if (d == Double.NEGATIVE_INFINITY)
|
||||
{
|
||||
//d == -Infinity
|
||||
if (negativePrefix != '\uFFFF')
|
||||
s.append(negativePrefix);
|
||||
s.append(INFINITY);
|
||||
if (negativeSuffix != '\uFFFF')
|
||||
s.append(negativeSuffix);
|
||||
}
|
||||
else if (d == Double.POSITIVE_INFINITY)
|
||||
//d == Infinity
|
||||
s.append(INFINITY);
|
||||
else if (d != d)
|
||||
//d == NaN
|
||||
s.append(NaN);
|
||||
else if (d == 0.0)
|
||||
{
|
||||
if ( (Double.doubleToLongBits(d) & DoubleSignMask) != 0)
|
||||
{
|
||||
//d == -0.0
|
||||
if (negativePrefix != '\uFFFF')
|
||||
s.append(negativePrefix);
|
||||
s.append('0').append(decimalPoint).append(ZEROS[numFractDigits]);
|
||||
if (negativeSuffix != '\uFFFF')
|
||||
s.append(negativeSuffix);
|
||||
}
|
||||
else
|
||||
//d == 0.0
|
||||
s.append('0').append(decimalPoint).append(ZEROS[numFractDigits]);
|
||||
}
|
||||
else
|
||||
{
|
||||
//convert to a positive format, and record whether we have a negative
|
||||
//number so that we know later whether to add the negativeSuffix
|
||||
boolean negative = false;
|
||||
if (d < 0)
|
||||
{
|
||||
//Even if the number is negative, we only need to set the
|
||||
//negative flag if there is a printable negativeSuffix
|
||||
if (negativeSuffix != '\uFFFF')
|
||||
negative = true;
|
||||
if (negativePrefix != '\uFFFF')
|
||||
s.append(negativePrefix);
|
||||
d = -d;
|
||||
}
|
||||
|
||||
//Find the magnitude. This is basically the exponent in normal form.
|
||||
int magnitude = magnitude(d);
|
||||
|
||||
//First off, if the number is too small for the given format, we
|
||||
//only print 0.0..., which makes this real quick
|
||||
if ( (magnitude + numFractDigits) < 0)
|
||||
{
|
||||
appendNearlyZeroNumber(s, d, magnitude, numFractDigits, decimalPoint);
|
||||
if (negative)
|
||||
s.append(negativeSuffix);
|
||||
return;
|
||||
}
|
||||
|
||||
long l;
|
||||
//Now scale the double to the biggest long value we need
|
||||
//We need to handle the smallest magnitudes differently because of rounding errors
|
||||
|
||||
//This test is unlikely to ever be true. It would require numFractDigits
|
||||
//to be 305 or more, which is pretty unlikely.
|
||||
if (magnitude < -305)
|
||||
l = (long) ((d*1E18) / d_tenthPowers[magnitude + 324]);
|
||||
else
|
||||
l = (long) (d / d_tenthPowers[magnitude + 323 - 17]);
|
||||
|
||||
//And round up if necessary. Add one to the numFractDigits digit if the
|
||||
//numFractDigits+1 digit is 5 or greater. It is useful to know that
|
||||
//given a long, l, the nth digit is obtained using the formula
|
||||
// nthDigit = (l/(tenthPower(l)/l_tenthPowers[n-1]))%10;
|
||||
|
||||
long l_tenthPower = tenthPower(l);
|
||||
//The numFractDigits+1 digit of the double is the
|
||||
//numFractDigits+1+magnitude digit of the long.
|
||||
//We only need worry about digits within the long. Very large numbers are
|
||||
//not rounded because all the digits after the decimal points are 0 anyway
|
||||
if (numFractDigits+magnitude+1 < l_tenthPowers.length)
|
||||
{
|
||||
long digit = (l/(l_tenthPower/l_tenthPowers[numFractDigits+magnitude+1]))%10;
|
||||
if (digit >= 5)
|
||||
{
|
||||
l += l_tenthPower/l_tenthPowers[numFractDigits+magnitude];
|
||||
}
|
||||
}
|
||||
|
||||
//And now we just print out our long, with the decimal point character
|
||||
//inserted in the right place, using as many places as we wanted.
|
||||
appendAsDouble(s, l, l_tenthPower, magnitude, numFractDigits, decimalPoint, thousandsSeparator,
|
||||
numDigitsSeparated, negativePrefix, negativeSuffix);
|
||||
|
||||
//Finally, append the negativeSuffix if necessary
|
||||
if (negative)
|
||||
s.append(negativeSuffix);
|
||||
}
|
||||
}
|
||||
|
||||
public void appendAsDouble(StringBuffer s, long l, long l_mag, int d_magnitude,
|
||||
int numFractDigits, char decimalPoint, char thousandsSeparator,
|
||||
int numDigitsSeparated, char negativePrefix, char negativeSuffix)
|
||||
{
|
||||
//If the magnitude is negative, we have a 0.xxx number
|
||||
if (d_magnitude < 0)
|
||||
{
|
||||
s.append('0').append(decimalPoint).append(ZEROS[-d_magnitude-1]);
|
||||
//And just print successive digits until we have reached numFractDigits
|
||||
//First decrement numFractDigits by the number of digits already printed
|
||||
numFractDigits += d_magnitude;
|
||||
|
||||
//get the magnitude of l
|
||||
long c;
|
||||
while(numFractDigits-- >= 0)
|
||||
{
|
||||
//Get the leading character (e.g. '62345/10000 = 6' using integer-divide)
|
||||
c = l/l_mag;
|
||||
//Append the digit character for this digit (e.g. number is 6, so character is '6')
|
||||
s.append(charForDigit[(int) c]);
|
||||
//Multiply by the leading digit by the magnitude so that we can eliminate the leading digit
|
||||
//(e.g. 6 * 10000 = 60000)
|
||||
c *= l_mag;
|
||||
//and eliminate the leading digit (e.g. 62345-60000 = 2345)
|
||||
if ( c <= l)
|
||||
l -= c;
|
||||
//Decrease the magnitude by 10, and repeat the loop.
|
||||
l_mag = l_mag/10;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
//Just keep printing until magnitude is 0
|
||||
long c;
|
||||
while(d_magnitude-- >= 0)
|
||||
{
|
||||
if (l_mag == 0) {s.append('0');continue;}
|
||||
//Get the leading character (e.g. '62345/10000 = 6' using integer-divide)
|
||||
c = l/l_mag;
|
||||
//Append the digit character for this digit (e.g. number is 6, so character is '6')
|
||||
s.append(charForDigit[(int) c]);
|
||||
|
||||
//Don't forget about the thousands separator
|
||||
if (d_magnitude % numDigitsSeparated == (numDigitsSeparated-1))
|
||||
s.append(thousandsSeparator);
|
||||
|
||||
//Multiply by the leading digit by the magnitude so that we can eliminate the leading digit
|
||||
//(e.g. 6 * 10000 = 60000)
|
||||
c *= l_mag;
|
||||
//and eliminate the leading digit (e.g. 62345-60000 = 2345)
|
||||
if ( c <= l)
|
||||
l -= c;
|
||||
//Decrease the magnitude by 10, and repeat the loop.
|
||||
l_mag = l_mag/10;
|
||||
}
|
||||
s.append(decimalPoint);
|
||||
if (l_mag == 0)
|
||||
s.append(ZEROS[numFractDigits]);
|
||||
else
|
||||
{
|
||||
while(numFractDigits-- > 0)
|
||||
{
|
||||
if (l_mag == 0) {s.append('0');continue;}
|
||||
//Get the leading character (e.g. '62345/10000 = 6' using integer-divide)
|
||||
c = l/l_mag;
|
||||
//Append the digit character for this digit (e.g. number is 6, so character is '6')
|
||||
s.append(charForDigit[(int) c]);
|
||||
//Multiply by the leading digit by the magnitude so that we can eliminate the leading digit
|
||||
//(e.g. 6 * 10000 = 60000)
|
||||
c *= l_mag;
|
||||
//and eliminate the leading digit (e.g. 62345-60000 = 2345)
|
||||
if ( c <= l)
|
||||
l -= c;
|
||||
//Decrease the magnitude by 10, and repeat the loop.
|
||||
l_mag = l_mag/10;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private void appendNearlyZeroNumber(StringBuffer s, double d, int d_magnitude,
|
||||
int numFractDigits, char decimalPoint)
|
||||
{
|
||||
if (d_magnitude + numFractDigits == -1)
|
||||
{
|
||||
//Possibly too small, depends on whether the top digit is 5 or greater
|
||||
//So we have to scale to get the leading digit
|
||||
int i;
|
||||
if (d_magnitude < -305)
|
||||
//Probably not necessary. Who is going to print 305 places?
|
||||
i = (int) ((d*1E19) / d_tenthPowers[d_magnitude + 324 + 18]);
|
||||
else
|
||||
i = (int) (d / d_tenthPowers[d_magnitude + 323]);
|
||||
|
||||
if (i >= 5)
|
||||
{
|
||||
//Not too small, we get to round up
|
||||
s.append('0').append(decimalPoint).append(ZEROS[numFractDigits-1]);
|
||||
s.append('1');
|
||||
}
|
||||
else
|
||||
{
|
||||
//Definitely too small. Just print zeros
|
||||
s.append('0').append(decimalPoint).append(ZEROS[numFractDigits]);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
//Definitely too small
|
||||
s.append('0').append(decimalPoint).append(ZEROS[numFractDigits]);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Assumes i is positive. Returns the magnitude of i in base 10.
|
||||
*/
|
||||
private static long tenthPower(long i)
|
||||
{
|
||||
if (i < 10L) return 1;
|
||||
else if (i < 100L) return 10L;
|
||||
else if (i < 1000L) return 100L;
|
||||
else if (i < 10000L) return 1000L;
|
||||
else if (i < 100000L) return 10000L;
|
||||
else if (i < 1000000L) return 100000L;
|
||||
else if (i < 10000000L) return 1000000L;
|
||||
else if (i < 100000000L) return 10000000L;
|
||||
else if (i < 1000000000L) return 100000000L;
|
||||
else if (i < 10000000000L) return 1000000000L;
|
||||
else if (i < 100000000000L) return 10000000000L;
|
||||
else if (i < 1000000000000L) return 100000000000L;
|
||||
else if (i < 10000000000000L) return 1000000000000L;
|
||||
else if (i < 100000000000000L) return 10000000000000L;
|
||||
else if (i < 1000000000000000L) return 100000000000000L;
|
||||
else if (i < 10000000000000000L) return 1000000000000000L;
|
||||
else if (i < 100000000000000000L) return 10000000000000000L;
|
||||
else if (i < 1000000000000000000L) return 100000000000000000L;
|
||||
else return 1000000000000000000L;
|
||||
}
|
||||
|
||||
|
||||
private static int magnitude(double d)
|
||||
{
|
||||
//It works. What else can I say.
|
||||
long doubleToLongBits = Double.doubleToLongBits(d);
|
||||
int magnitude =
|
||||
(int) ((((doubleToLongBits & DoubleExpMask) >> DoubleExpShift) - DoubleExpBias) * 0.301029995663981);
|
||||
|
||||
if (magnitude < -323)
|
||||
magnitude = -323;
|
||||
else if (magnitude > 308)
|
||||
magnitude = 308;
|
||||
|
||||
if (d >= d_tenthPowers[magnitude+323])
|
||||
{
|
||||
while(magnitude < 309 && d >= d_tenthPowers[magnitude+323])
|
||||
magnitude++;
|
||||
magnitude--;
|
||||
return magnitude;
|
||||
}
|
||||
else
|
||||
{
|
||||
while(magnitude > -324 && d < d_tenthPowers[magnitude+323])
|
||||
magnitude--;
|
||||
return magnitude;
|
||||
}
|
||||
}
|
||||
|
||||
static long[] l_tenthPowers = {
|
||||
1,
|
||||
10L,
|
||||
100L,
|
||||
1000L,
|
||||
10000L,
|
||||
100000L,
|
||||
1000000L,
|
||||
10000000L,
|
||||
100000000L,
|
||||
1000000000L,
|
||||
10000000000L,
|
||||
100000000000L,
|
||||
1000000000000L,
|
||||
10000000000000L,
|
||||
100000000000000L,
|
||||
1000000000000000L,
|
||||
10000000000000000L,
|
||||
100000000000000000L,
|
||||
1000000000000000000L,
|
||||
};
|
||||
|
||||
public static void append(StringBuffer s, double d)
|
||||
{
|
||||
if (d == Double.NEGATIVE_INFINITY)
|
||||
s.append(NEGATIVE_INFINITY);
|
||||
else if (d == Double.POSITIVE_INFINITY)
|
||||
s.append(POSITIVE_INFINITY);
|
||||
else if (d != d)
|
||||
s.append(NaN);
|
||||
else if (d == 0.0)
|
||||
{
|
||||
if ( (Double.doubleToLongBits(d) & DoubleSignMask) != 0)
|
||||
s.append('-');
|
||||
s.append(DOUBLE_ZERO);
|
||||
}
|
||||
else
|
||||
{
|
||||
if (d < 0)
|
||||
{
|
||||
s.append('-');
|
||||
d = -d;
|
||||
}
|
||||
|
||||
if (d >= 0.001 && d < 0.01)
|
||||
{
|
||||
long i = (long) (d * 1E20);
|
||||
i = i%100 >= 50 ? (i/100) + 1 : i/100;
|
||||
s.append(DOUBLE_ZERO2);
|
||||
appendFractDigits(s, i,-1);
|
||||
}
|
||||
else if (d >= 0.01 && d < 0.1)
|
||||
{
|
||||
long i = (long) (d * 1E19);
|
||||
i = i%100 >= 50 ? (i/100) + 1 : i/100;
|
||||
s.append(DOUBLE_ZERO);
|
||||
appendFractDigits(s, i,-1);
|
||||
}
|
||||
else if (d >= 0.1 && d < 1)
|
||||
{
|
||||
long i = (long) (d * 1E18);
|
||||
i = i%100 >= 50 ? (i/100) + 1 : i/100;
|
||||
s.append(DOUBLE_ZERO0);
|
||||
appendFractDigits(s, i,-1);
|
||||
}
|
||||
else if (d >= 1 && d < 10)
|
||||
{
|
||||
long i = (long) (d * 1E17);
|
||||
i = i%100 >= 50 ? (i/100) + 1 : i/100;
|
||||
appendFractDigits(s, i,1);
|
||||
}
|
||||
else if (d >= 10 && d < 100)
|
||||
{
|
||||
long i = (long) (d * 1E16);
|
||||
i = i%100 >= 50 ? (i/100) + 1 : i/100;
|
||||
appendFractDigits(s, i,2);
|
||||
}
|
||||
else if (d >= 100 && d < 1000)
|
||||
{
|
||||
long i = (long) (d * 1E15);
|
||||
i = i%100 >= 50 ? (i/100) + 1 : i/100;
|
||||
appendFractDigits(s, i,3);
|
||||
}
|
||||
else if (d >= 1000 && d < 10000)
|
||||
{
|
||||
long i = (long) (d * 1E14);
|
||||
i = i%100 >= 50 ? (i/100) + 1 : i/100;
|
||||
appendFractDigits(s, i,4);
|
||||
}
|
||||
else if (d >= 10000 && d < 100000)
|
||||
{
|
||||
long i = (long) (d * 1E13);
|
||||
i = i%100 >= 50 ? (i/100) + 1 : i/100;
|
||||
appendFractDigits(s, i,5);
|
||||
}
|
||||
else if (d >= 100000 && d < 1000000)
|
||||
{
|
||||
long i = (long) (d * 1E12);
|
||||
i = i%100 >= 50 ? (i/100) + 1 : i/100;
|
||||
appendFractDigits(s, i,6);
|
||||
}
|
||||
else if (d >= 1000000 && d < 10000000)
|
||||
{
|
||||
long i = (long) (d * 1E11);
|
||||
i = i%100 >= 50 ? (i/100) + 1 : i/100;
|
||||
appendFractDigits(s, i,7);
|
||||
}
|
||||
else if (d == Double.MIN_VALUE)
|
||||
s.append("4.9E-324");
|
||||
else if (d == Double.MAX_VALUE)
|
||||
s.append("1.7976931348623157E308");
|
||||
else
|
||||
{
|
||||
int magnitude = magnitude(d);
|
||||
long i;
|
||||
if (magnitude < -305)
|
||||
i = (long) (d*1E18 / d_tenthPowers[magnitude + 324]);
|
||||
else
|
||||
i = (long) (d / d_tenthPowers[magnitude + 323 - 17]);
|
||||
i = i%100 >= 50 ? (i/100) + 1 : i/100;
|
||||
appendFractDigits(s, i, 1);
|
||||
s.append('E');
|
||||
append(s,magnitude);
|
||||
}
|
||||
}
|
||||
}
|
||||
public static void append(StringBuffer s, int i)
|
||||
{
|
||||
if (i < 0)
|
||||
{
|
||||
if (i == Integer.MIN_VALUE)
|
||||
{
|
||||
//cannot make this positive due to integer overflow
|
||||
s.append("-2147483648");
|
||||
}
|
||||
s.append('-');
|
||||
i = -i;
|
||||
}
|
||||
int mag;
|
||||
int c;
|
||||
if (i < 10)
|
||||
{
|
||||
//one digit
|
||||
s.append(charForDigit[i]);
|
||||
}
|
||||
else if (i < 100)
|
||||
{
|
||||
//two digits
|
||||
s.append(charForDigit[i/10]);
|
||||
s.append(charForDigit[i%10]);
|
||||
}
|
||||
else if (i < 1000)
|
||||
{
|
||||
//three digits
|
||||
s.append(charForDigit[i/100]);
|
||||
s.append(charForDigit[(c=i%100)/10]);
|
||||
s.append(charForDigit[c%10]);
|
||||
}
|
||||
else if (i < 10000)
|
||||
{
|
||||
//four digits
|
||||
s.append(charForDigit[i/1000]);
|
||||
s.append(charForDigit[(c=i%1000)/100]);
|
||||
s.append(charForDigit[(c%=100)/10]);
|
||||
s.append(charForDigit[c%10]);
|
||||
}
|
||||
else if (i < 100000)
|
||||
{
|
||||
//five digits
|
||||
s.append(charForDigit[i/10000]);
|
||||
s.append(charForDigit[(c=i%10000)/1000]);
|
||||
s.append(charForDigit[(c%=1000)/100]);
|
||||
s.append(charForDigit[(c%=100)/10]);
|
||||
s.append(charForDigit[c%10]);
|
||||
}
|
||||
else if (i < 1000000)
|
||||
{
|
||||
//six digits
|
||||
s.append(charForDigit[i/100000]);
|
||||
s.append(charForDigit[(c=i%100000)/10000]);
|
||||
s.append(charForDigit[(c%=10000)/1000]);
|
||||
s.append(charForDigit[(c%=1000)/100]);
|
||||
s.append(charForDigit[(c%=100)/10]);
|
||||
s.append(charForDigit[c%10]);
|
||||
}
|
||||
else if (i < 10000000)
|
||||
{
|
||||
//seven digits
|
||||
s.append(charForDigit[i/1000000]);
|
||||
s.append(charForDigit[(c=i%1000000)/100000]);
|
||||
s.append(charForDigit[(c%=100000)/10000]);
|
||||
s.append(charForDigit[(c%=10000)/1000]);
|
||||
s.append(charForDigit[(c%=1000)/100]);
|
||||
s.append(charForDigit[(c%=100)/10]);
|
||||
s.append(charForDigit[c%10]);
|
||||
}
|
||||
else if (i < 100000000)
|
||||
{
|
||||
//eight digits
|
||||
s.append(charForDigit[i/10000000]);
|
||||
s.append(charForDigit[(c=i%10000000)/1000000]);
|
||||
s.append(charForDigit[(c%=1000000)/100000]);
|
||||
s.append(charForDigit[(c%=100000)/10000]);
|
||||
s.append(charForDigit[(c%=10000)/1000]);
|
||||
s.append(charForDigit[(c%=1000)/100]);
|
||||
s.append(charForDigit[(c%=100)/10]);
|
||||
s.append(charForDigit[c%10]);
|
||||
}
|
||||
else if (i < 1000000000)
|
||||
{
|
||||
//nine digits
|
||||
s.append(charForDigit[i/100000000]);
|
||||
s.append(charForDigit[(c=i%100000000)/10000000]);
|
||||
s.append(charForDigit[(c%=10000000)/1000000]);
|
||||
s.append(charForDigit[(c%=1000000)/100000]);
|
||||
s.append(charForDigit[(c%=100000)/10000]);
|
||||
s.append(charForDigit[(c%=10000)/1000]);
|
||||
s.append(charForDigit[(c%=1000)/100]);
|
||||
s.append(charForDigit[(c%=100)/10]);
|
||||
s.append(charForDigit[c%10]);
|
||||
}
|
||||
else
|
||||
{
|
||||
//ten digits
|
||||
s.append(charForDigit[i/1000000000]);
|
||||
s.append(charForDigit[(c=i%1000000000)/100000000]);
|
||||
s.append(charForDigit[(c%=100000000)/10000000]);
|
||||
s.append(charForDigit[(c%=10000000)/1000000]);
|
||||
s.append(charForDigit[(c%=1000000)/100000]);
|
||||
s.append(charForDigit[(c%=100000)/10000]);
|
||||
s.append(charForDigit[(c%=10000)/1000]);
|
||||
s.append(charForDigit[(c%=1000)/100]);
|
||||
s.append(charForDigit[(c%=100)/10]);
|
||||
s.append(charForDigit[c%10]);
|
||||
}
|
||||
}
|
||||
private static void appendFractDigits(StringBuffer s, long i, int decimalOffset)
|
||||
{
|
||||
long mag = tenthPower(i);
|
||||
long c;
|
||||
while ( i > 0 )
|
||||
{
|
||||
c = i/mag;
|
||||
s.append(charForDigit[(int) c]);
|
||||
decimalOffset--;
|
||||
if (decimalOffset == 0)
|
||||
s.append('.');
|
||||
c *= mag;
|
||||
if ( c <= i)
|
||||
i -= c;
|
||||
mag = mag/10;
|
||||
}
|
||||
if (i != 0)
|
||||
s.append(charForDigit[(int) i]);
|
||||
else if (decimalOffset > 0)
|
||||
{
|
||||
s.append(ZEROS[decimalOffset]);
|
||||
decimalOffset = 1;
|
||||
}
|
||||
|
||||
decimalOffset--;
|
||||
if (decimalOffset == 0)
|
||||
s.append(DOT_ZERO);
|
||||
else if (decimalOffset == -1)
|
||||
s.append('0');
|
||||
}
|
||||
|
||||
public static final char[] NEGATIVE_INFINITY = {'-','I','n','f','i','n','i','t','y'};
|
||||
public static final char[] POSITIVE_INFINITY = {'I','n','f','i','n','i','t','y'};
|
||||
public static final char[] DOUBLE_ZERO = {'0','.','0'};
|
||||
public static final char[] DOUBLE_ZERO2 = {'0','.','0','0'};
|
||||
public static final char[] DOUBLE_ZERO0 = {'0','.'};
|
||||
public static final char[] DOT_ZERO = {'.','0'};
|
||||
|
||||
}
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
Copyright (C) 2003, 2005, 2006 Jeroen Frijters
|
||||
Copyright (C) 2003, 2005, 2006, 2007 Jeroen Frijters
|
||||
|
||||
This software is provided 'as-is', without any express or implied
|
||||
warranty. In no event will the authors be held liable for any damages
|
||||
|
@ -25,8 +25,7 @@
|
|||
package java.lang;
|
||||
|
||||
import cli.System.BitConverter;
|
||||
import cli.System.Globalization.CultureInfo;
|
||||
import ikvm.lang.CIL;
|
||||
import sun.misc.FloatingDecimal;
|
||||
|
||||
final class VMDouble
|
||||
{
|
||||
|
@ -51,55 +50,12 @@ final class VMDouble
|
|||
|
||||
static String toString(double d, boolean isFloat)
|
||||
{
|
||||
if(isFloat)
|
||||
{
|
||||
float f = (float)d;
|
||||
if(Float.isNaN(f))
|
||||
{
|
||||
return "NaN";
|
||||
}
|
||||
if(Float.isInfinite(f))
|
||||
{
|
||||
return f < 0f ? "-Infinity" : "Infinity";
|
||||
}
|
||||
if(f == 0f)
|
||||
{
|
||||
return BitConverter.DoubleToInt64Bits(d) < 0 ? "-0.0" : "0.0";
|
||||
}
|
||||
// TODO this is not correct, we need to use the Java algorithm of converting a float to string
|
||||
// HACK really lame hack to approximate the Java behavior a little bit
|
||||
String s = CIL.box_float(f).ToString(CultureInfo.get_InvariantCulture());
|
||||
if(s.indexOf('.') == -1)
|
||||
{
|
||||
int e = s.indexOf('E');
|
||||
if(e == -1)
|
||||
{
|
||||
s += ".0";
|
||||
}
|
||||
else
|
||||
{
|
||||
int plus = s.charAt(e + 1) == '+' ? 1 : 0;
|
||||
s = s.substring(0, e) + ".0E" + Integer.parseInt(s.substring(e + 1 + plus));
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
int e = s.indexOf('E');
|
||||
if(e != -1)
|
||||
{
|
||||
int plus = s.charAt(e + 1) == '+' ? 1 : 0;
|
||||
s = s.substring(0, e) + "E" + Integer.parseInt(s.substring(e + 1 + plus));
|
||||
}
|
||||
}
|
||||
return s;
|
||||
}
|
||||
else
|
||||
{
|
||||
StringBuffer sb = new StringBuffer();
|
||||
DoubleToString.append(sb, d);
|
||||
return sb.toString();
|
||||
}
|
||||
assert !isFloat;
|
||||
return new FloatingDecimal(d).toJavaFormatString();
|
||||
}
|
||||
|
||||
static native double parseDouble(String s);
|
||||
static double parseDouble(String s)
|
||||
{
|
||||
return FloatingDecimal.readJavaFormatString(s).doubleValue();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
Copyright (C) 2003 Jeroen Frijters
|
||||
Copyright (C) 2003, 2007 Jeroen Frijters
|
||||
|
||||
This software is provided 'as-is', without any express or implied
|
||||
warranty. In no event will the authors be held liable for any damages
|
||||
|
@ -24,6 +24,8 @@
|
|||
|
||||
package java.lang;
|
||||
|
||||
import sun.misc.FloatingDecimal;
|
||||
|
||||
final class VMFloat
|
||||
{
|
||||
static float intBitsToFloat(int v)
|
||||
|
@ -44,4 +46,14 @@ final class VMFloat
|
|||
{
|
||||
return cli.System.BitConverter.ToInt32(cli.System.BitConverter.GetBytes(v), 0);
|
||||
}
|
||||
|
||||
static String toString(float f)
|
||||
{
|
||||
return new FloatingDecimal(f).toJavaFormatString();
|
||||
}
|
||||
|
||||
static float parseFloat(String str)
|
||||
{
|
||||
return FloatingDecimal.readJavaFormatString(str).floatValue();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,118 @@
|
|||
/*
|
||||
* Copyright 2003 Sun Microsystems, Inc. All Rights Reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation. Sun designates this
|
||||
* particular file as subject to the "Classpath" exception as provided
|
||||
* by Sun in the LICENSE file that accompanied this code.
|
||||
*
|
||||
* This code 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 General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
|
||||
* CA 95054 USA or visit www.sun.com if you need additional information or
|
||||
* have any questions.
|
||||
*/
|
||||
|
||||
package sun.misc;
|
||||
|
||||
/**
|
||||
* This class contains additional constants documenting limits of the
|
||||
* <code>double</code> type.
|
||||
*
|
||||
* @author Joseph D. Darcy
|
||||
* @version 1.7, 05/05/07
|
||||
*/
|
||||
|
||||
public class DoubleConsts {
|
||||
/**
|
||||
* Don't let anyone instantiate this class.
|
||||
*/
|
||||
private DoubleConsts() {}
|
||||
|
||||
public static final double POSITIVE_INFINITY = java.lang.Double.POSITIVE_INFINITY;
|
||||
public static final double NEGATIVE_INFINITY = java.lang.Double.NEGATIVE_INFINITY;
|
||||
public static final double NaN = java.lang.Double.NaN;
|
||||
public static final double MAX_VALUE = java.lang.Double.MAX_VALUE;
|
||||
public static final double MIN_VALUE = java.lang.Double.MIN_VALUE;
|
||||
|
||||
/**
|
||||
* A constant holding the smallest positive normal value of type
|
||||
* <code>double</code>, 2<sup>-1022</sup>. It is equal to the
|
||||
* value returned by
|
||||
* <code>Double.longBitsToDouble(0x0010000000000000L)</code>.
|
||||
*
|
||||
* @since 1.5
|
||||
*/
|
||||
public static final double MIN_NORMAL = 2.2250738585072014E-308;
|
||||
|
||||
|
||||
/**
|
||||
* The number of logical bits in the significand of a
|
||||
* <code>double</code> number, including the implicit bit.
|
||||
*/
|
||||
public static final int SIGNIFICAND_WIDTH = 53;
|
||||
|
||||
/**
|
||||
* Maximum exponent a finite <code>double</code> number may have.
|
||||
* It is equal to the value returned by
|
||||
* <code>Math.ilogb(Double.MAX_VALUE)</code>.
|
||||
*/
|
||||
public static final int MAX_EXPONENT = 1023;
|
||||
|
||||
/**
|
||||
* Minimum exponent a normalized <code>double</code> number may
|
||||
* have. It is equal to the value returned by
|
||||
* <code>Math.ilogb(Double.MIN_NORMAL)</code>.
|
||||
*/
|
||||
public static final int MIN_EXPONENT = -1022;
|
||||
|
||||
/**
|
||||
* The exponent the smallest positive <code>double</code>
|
||||
* subnormal value would have if it could be normalized. It is
|
||||
* equal to the value returned by
|
||||
* <code>FpUtils.ilogb(Double.MIN_VALUE)</code>.
|
||||
*/
|
||||
public static final int MIN_SUB_EXPONENT = MIN_EXPONENT -
|
||||
(SIGNIFICAND_WIDTH - 1);
|
||||
|
||||
/**
|
||||
* Bias used in representing a <code>double</code> exponent.
|
||||
*/
|
||||
public static final int EXP_BIAS = 1023;
|
||||
|
||||
/**
|
||||
* Bit mask to isolate the sign bit of a <code>double</code>.
|
||||
*/
|
||||
public static final long SIGN_BIT_MASK = 0x8000000000000000L;
|
||||
|
||||
/**
|
||||
* Bit mask to isolate the exponent field of a
|
||||
* <code>double</code>.
|
||||
*/
|
||||
public static final long EXP_BIT_MASK = 0x7FF0000000000000L;
|
||||
|
||||
/**
|
||||
* Bit mask to isolate the significand field of a
|
||||
* <code>double</code>.
|
||||
*/
|
||||
public static final long SIGNIF_BIT_MASK = 0x000FFFFFFFFFFFFFL;
|
||||
|
||||
static {
|
||||
// verify bit masks cover all bit positions and that the bit
|
||||
// masks are non-overlapping
|
||||
assert(((SIGN_BIT_MASK | EXP_BIT_MASK | SIGNIF_BIT_MASK) == ~0L) &&
|
||||
(((SIGN_BIT_MASK & EXP_BIT_MASK) == 0L) &&
|
||||
((SIGN_BIT_MASK & SIGNIF_BIT_MASK) == 0L) &&
|
||||
((EXP_BIT_MASK & SIGNIF_BIT_MASK) == 0L)));
|
||||
}
|
||||
}
|
|
@ -0,0 +1,113 @@
|
|||
/*
|
||||
* Copyright 2003 Sun Microsystems, Inc. All Rights Reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation. Sun designates this
|
||||
* particular file as subject to the "Classpath" exception as provided
|
||||
* by Sun in the LICENSE file that accompanied this code.
|
||||
*
|
||||
* This code 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 General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
|
||||
* CA 95054 USA or visit www.sun.com if you need additional information or
|
||||
* have any questions.
|
||||
*/
|
||||
|
||||
package sun.misc;
|
||||
|
||||
/**
|
||||
* This class contains additional constants documenting limits of the
|
||||
* <code>float</code> type.
|
||||
*
|
||||
* @author Joseph D. Darcy
|
||||
* @version 1.7, 05/05/07
|
||||
*/
|
||||
|
||||
public class FloatConsts {
|
||||
/**
|
||||
* Don't let anyone instantiate this class.
|
||||
*/
|
||||
private FloatConsts() {}
|
||||
|
||||
public static final float POSITIVE_INFINITY = java.lang.Float.POSITIVE_INFINITY;
|
||||
public static final float NEGATIVE_INFINITY = java.lang.Float.NEGATIVE_INFINITY;
|
||||
public static final float NaN = java.lang.Float.NaN;
|
||||
public static final float MAX_VALUE = java.lang.Float.MAX_VALUE;
|
||||
public static final float MIN_VALUE = java.lang.Float.MIN_VALUE;
|
||||
|
||||
/**
|
||||
* A constant holding the smallest positive normal value of type
|
||||
* <code>float</code>, 2<sup>-126</sup>. It is equal to the value
|
||||
* returned by <code>Float.intBitsToFloat(0x00800000)</code>.
|
||||
*/
|
||||
public static final float MIN_NORMAL = 1.17549435E-38f;
|
||||
|
||||
/**
|
||||
* The number of logical bits in the significand of a
|
||||
* <code>float</code> number, including the implicit bit.
|
||||
*/
|
||||
public static final int SIGNIFICAND_WIDTH = 24;
|
||||
|
||||
/**
|
||||
* Maximum exponent a finite <code>float</code> number may have.
|
||||
* It is equal to the value returned by
|
||||
* <code>Math.ilogb(Float.MAX_VALUE)</code>.
|
||||
*/
|
||||
public static final int MAX_EXPONENT = 127;
|
||||
|
||||
/**
|
||||
* Minimum exponent a normalized <code>float</code> number may
|
||||
* have. It is equal to the value returned by
|
||||
* <code>Math.ilogb(Float.MIN_NORMAL)</code>.
|
||||
*/
|
||||
public static final int MIN_EXPONENT = -126;
|
||||
|
||||
/**
|
||||
* The exponent the smallest positive <code>float</code> subnormal
|
||||
* value would have if it could be normalized. It is equal to the
|
||||
* value returned by <code>FpUtils.ilogb(Float.MIN_VALUE)</code>.
|
||||
*/
|
||||
public static final int MIN_SUB_EXPONENT = MIN_EXPONENT -
|
||||
(SIGNIFICAND_WIDTH - 1);
|
||||
|
||||
/**
|
||||
* Bias used in representing a <code>float</code> exponent.
|
||||
*/
|
||||
public static final int EXP_BIAS = 127;
|
||||
|
||||
/**
|
||||
* Bit mask to isolate the sign bit of a <code>float</code>.
|
||||
*/
|
||||
public static final int SIGN_BIT_MASK = 0x80000000;
|
||||
|
||||
/**
|
||||
* Bit mask to isolate the exponent field of a
|
||||
* <code>float</code>.
|
||||
*/
|
||||
public static final int EXP_BIT_MASK = 0x7F800000;
|
||||
|
||||
/**
|
||||
* Bit mask to isolate the significand field of a
|
||||
* <code>float</code>.
|
||||
*/
|
||||
public static final int SIGNIF_BIT_MASK = 0x007FFFFF;
|
||||
|
||||
static {
|
||||
// verify bit masks cover all bit positions and that the bit
|
||||
// masks are non-overlapping
|
||||
assert(((SIGN_BIT_MASK | EXP_BIT_MASK | SIGNIF_BIT_MASK) == ~0) &&
|
||||
(((SIGN_BIT_MASK & EXP_BIT_MASK) == 0) &&
|
||||
((SIGN_BIT_MASK & SIGNIF_BIT_MASK) == 0) &&
|
||||
((EXP_BIT_MASK & SIGNIF_BIT_MASK) == 0)));
|
||||
}
|
||||
}
|
Разница между файлами не показана из-за своего большого размера
Загрузить разницу
Разница между файлами не показана из-за своего большого размера
Загрузить разницу
|
@ -369,109 +369,6 @@ namespace IKVM.NativeCode.java
|
|||
}
|
||||
}
|
||||
|
||||
public class VMDouble
|
||||
{
|
||||
public static double parseDouble(string s)
|
||||
{
|
||||
if(s.Length == 0) goto error;
|
||||
int first = 0;
|
||||
while(s[first] <= ' ')
|
||||
{
|
||||
first++;
|
||||
if(first == s.Length) goto error;
|
||||
}
|
||||
int last = s.Length - 1;
|
||||
while(s[last] <= ' ')
|
||||
{
|
||||
last--;
|
||||
if(first > last) goto error;
|
||||
}
|
||||
bool sign = false;
|
||||
if(s[first] == '-')
|
||||
{
|
||||
sign = true;
|
||||
first++;
|
||||
if(first > last) goto error;
|
||||
}
|
||||
else if(s[first] == '+')
|
||||
{
|
||||
first++;
|
||||
if(first > last) goto error;
|
||||
}
|
||||
if(last - first == 7 && string.CompareOrdinal(s, first, "Infinity", 0, 8) == 0)
|
||||
{
|
||||
return sign ? double.NegativeInfinity : double.PositiveInfinity;
|
||||
}
|
||||
if(last - first == 2 && string.CompareOrdinal(s, first, "NaN", 0, 3) == 0)
|
||||
{
|
||||
return double.NaN;
|
||||
}
|
||||
// Java allows 'f' or 'd' at the end
|
||||
if("dfDF".IndexOf(s[last]) >= 0)
|
||||
{
|
||||
last--;
|
||||
if(first > last) goto error;
|
||||
}
|
||||
bool dot = false;
|
||||
bool exp = false;
|
||||
for(int i = first; i <= last; i++)
|
||||
{
|
||||
char c = s[i];
|
||||
if(c >= '0' && c <= '9')
|
||||
{
|
||||
// ok
|
||||
}
|
||||
else if(c == '.')
|
||||
{
|
||||
if(dot || exp) goto error;
|
||||
dot = true;
|
||||
}
|
||||
else if(c == 'e' || c == 'E')
|
||||
{
|
||||
if(i == first || i == last || exp) goto error;
|
||||
if(s[i + 1] == '-' || s[i + 1] == '+')
|
||||
{
|
||||
i++;
|
||||
if(i == last) goto error;
|
||||
}
|
||||
exp = true;
|
||||
}
|
||||
else goto error;
|
||||
}
|
||||
if(first != 0 || last != s.Length - 1)
|
||||
{
|
||||
s = s.Substring(first, last - first + 1);
|
||||
}
|
||||
try
|
||||
{
|
||||
// I doubt that this is fully correct, but since we don't implement FP properly,
|
||||
// we can probably get away with this as well.
|
||||
double d = double.Parse(s, System.Globalization.CultureInfo.InvariantCulture);
|
||||
if(d == 0.0 && (s == "4.9E-324" || s == "4.9e-324"))
|
||||
{
|
||||
// HACK special support for Double.MIN_VALUE
|
||||
return sign ? -double.Epsilon : double.Epsilon;
|
||||
}
|
||||
return sign ? -d : d;
|
||||
}
|
||||
catch(OverflowException)
|
||||
{
|
||||
return sign ? double.NegativeInfinity : double.PositiveInfinity;
|
||||
}
|
||||
catch(FormatException x)
|
||||
{
|
||||
// this can't happen, since we already validated the format of the string
|
||||
System.Diagnostics.Debug.Fail(x.ToString());
|
||||
}
|
||||
error:
|
||||
#if !FIRST_PASS
|
||||
throw new NumberFormatException(string.Format("For input string: \"{0}\"", s));
|
||||
#else
|
||||
return 0;
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
public class VMSystem
|
||||
{
|
||||
public static void arraycopy(object src, int srcStart, object dest, int destStart, int len)
|
||||
|
|
Загрузка…
Ссылка в новой задаче