Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon. Entire thread

math.Nextafter(0,1)

Name: Anonymous 2011-12-20 13:47

Why is math.Nextafter(0, 1) = 5e-324?

Name: Anonymous 2011-12-20 14:14

You mean nextAfter?
And probably because it's smallest value representable as a java float.

Name: Anonymous 2011-12-20 14:44

Yeah, that's it. And I know it's the smallest value represented as a Java float (although I discovered this while experimenting with Go). I was confused because 5e-324 is a negative number, or am I misinterpreting the 'e'? Is it the irrational number 'e' or does it mean something else?

Name: Anonymous 2011-12-20 14:54

e is the exponent in base 10
5 e-324 is 5*10^-324 small and non negative

Name: Anonymous 2011-12-20 15:01

Thank you

Name: Anonymous 2011-12-20 15:22

http://www.docjar.com/html/api/java/lang/Math.java.html

1353       public static double nextAfter(double start, double direction) {
 1354           return sun.misc.FpUtils.nextAfter(start, direction);
 1355       }



http://www.java2s.com/Open-Source/Java-Document/6.0-JDK-Modules-sun/misc/sun/misc/FpUtils.java.htm


ENTERPRISE QUALITY CODE AHEAD

public static double nextAfter(double start, double direction) {
    /*
     * The cases:
     *
     * nextAfter(+infinity, 0)  == MAX_VALUE
     * nextAfter(+infinity, +infinity)  == +infinity
     * nextAfter(-infinity, 0)  == -MAX_VALUE
     * nextAfter(-infinity, -infinity)  == -infinity
     *
     * are naturally handled without any additional testing
     */

    // First check for NaN values
    if (isNaN(start) || isNaN(direction)) {
        // return a NaN derived from the input NaN(s)
        return start + direction;
    } else if (start == direction) {
        return direction;
    } else { // start > direction or start < direction
        // Add +0.0 to get rid of a -0.0 (+0.0 + -0.0 => +0.0)
        // then bitwise convert start to integer.
        long transducer = Double.doubleToRawLongBits(start + 0.0d);

        /*
         * IEEE 754 floating-point numbers are lexicographically
         * ordered if treated as signed- magnitude integers .
         * Since Java's integers are two's complement,
         * incrementing" the two's complement representation of a
         * logically negative floating-point value *decrements*
         * the signed-magnitude representation. Therefore, when
         * the integer representation of a floating-point values
         * is less than zero, the adjustment to the representation
         * is in the opposite direction than would be expected at
         * first .
         */
        if (direction > start) { // Calculate next greater value
            transducer = transducer + (transducer >= 0L ? 1L : -1L);
        } else { // Calculate next lesser value
            assert direction < start;
            if (transducer > 0L)
                --transducer;
            else if (transducer < 0L)
                ++transducer;
            /*
             * transducer==0, the result is -MIN_VALUE
             *
             * The transition from zero (implicitly
             * positive) to the smallest negative
             * signed magnitude value must be done
             * explicitly.
             */
            else
                transducer = DoubleConsts.SIGN_BIT_MASK | 1L;
        }

        return Double.longBitsToDouble(transducer);
    }
}



so in the case of (0,1) :


long transducer = Double.doubleToRawLongBits(start + 0.0d);
transducer = transducer + (transducer >= 0L ? 1L : -1L);
return Double.longBitsToDouble(transducer);


http://www.docjar.com/html/api/java/lang/Double.java.html

public static native long doubleToRawLongBits(double value);
public static native double longBitsToDouble(long bits);

Name: Anonymous 2011-12-20 15:28

>>6

/*
All of them comments
Comment to code ratio over 9,001
*/

Name: Anonymous 2011-12-20 15:32

>>7
that was just the comments inside the code, this gem was above it


/**
 * Returns the floating-point number adjacent to the first
 * argument in the direction of the second argument.  If both
 * arguments compare as equal the second argument is returned.
 *
 * <p>
 * Special cases:
 * <ul>
 * <li> If either argument is a NaN, then NaN is returned.
 *
 * <li> If both arguments are signed zeros, <code>direction</code>
 * is returned unchanged (as implied by the requirement of
 * returning the second argument if the arguments compare as
 * equal).
 *
 * <li> If <code>start</code> is
 * &plusmn;<code>Double.MIN_VALUE</code> and <code>direction</code>
 * has a value such that the result should have a smaller
 * magnitude, then a zero with the same sign as <code>start</code>
 * is returned.
 *
 * <li> If <code>start</code> is infinite and
 * <code>direction</code> has a value such that the result should
 * have a smaller magnitude, <code>Double.MAX_VALUE</code> with the
 * same sign as <code>start</code> is returned.
 *
 * <li> If <code>start</code> is equal to &plusmn;
 * <code>Double.MAX_VALUE</code> and <code>direction</code> has a
 * value such that the result should have a larger magnitude, an
 * infinity with same sign as <code>start</code> is returned.
 * </ul>
 *
 * @param start    starting floating-point value
 * @param direction value indicating which of
 * <code>start</code>'s neighbors or <code>start</code> should
 * be returned
 * @return The floating-point number adjacent to <code>start</code> in the
 * direction of <code>direction</code>.
 * @author Joseph D. Darcy
 */




ENTERPRISE COMMENTING BY JOSEPH D. DARCY

Name: Anonymous 2011-12-20 15:39

>>8
Joe is currently the lead engineer of Project Coin and specification lead for JSR 334, the effort to select and implement a set of small Java language changes for JDK 7. He has also served as a member of Sun's JDK 7 release team. From its inception in 2007 until March 20011, Joe was also the release manager, lead engineer, and quality lead for OpenJDK 6, an open source implementation of the Java SE 6 platform. A longtime member of the JDK engineering group, Joe was previously specification lead for JSR 269, the Pluggable Annotation Processing API, which delivered a standardized annotation processing API and mirror-based language model into JDK 6 to supersede the earlier apt tool from JDK 5. Joe assisted in implementing the JDK 5 language changes with work spanning core reflection, javac hacking, and general library support.

Name: Anonymous 2011-12-20 15:43

JOSEPH D. DARCY

PAST JOB: SENIOR STAFF ENGINEER AT SUN MICROSYSTEMS

DEMOTED TO: MEMBER OF THE TECHNICAL STAFF AT ORACLE CORPORATION


Joe is currently the lead engineer of Project Coin and specification lead for JSR 334, the effort to select and implement a set of small Java language changes for JDK 7. He has also served as a member of Sun's JDK 7 release team. From its inception in 2007 until March 20011, Joe was also the release manager, lead engineer, and quality lead for OpenJDK 6, an open source implementation of the Java SE 6 platform. A longtime member of the JDK engineering group, Joe was previously specification lead for JSR 269, the Pluggable Annotation Processing API, which delivered a standardized annotation processing API and mirror-based language model into JDK 6 to supersede the earlier apt tool from JDK 5. Joe assisted in implementing the JDK 5 language changes with work spanning core reflection, javac hacking, and general library support.


EDUCATION: MASTER'S DEGREE IN COMP SCI FROM UC BERKELEY
MORE EDUCATION: MASTER'S DEGREE IN APPLIED MATH FROM STANFORD
EVEN MORE ENTERPRISE EDUCATION: BS IN COMP SCI AT NEW JERSEY - NEW BRUNSWICK: SUMMA CUM LAUDE WITH HIGHEST HONORS IN COMP SCI AND PSYCHOLOGY

SPECIALTIES:

   JAVA PROGRAMMING LANGUAGE
   JAVA API DESIGN
   ANNOTATION PROCESSING
   IEEE 754 FLOATING-POINT


ACHIEVEMENTS:

JDK 5
  ENUM SUPPORT
  AUTOBOXING LIBRARY
  GENERICS, ENUMS, and ANNOTATION
  HEX FLOATING-POINT LITERAL SUPPORT
  EXPANDED JAVA MATH
    HYPERBOLICS
    CBRT
    HYPOT
    LOG10
    AND MORE ENTERPRISE WORK

Name: Joseph D. Darcy 2011-12-20 17:03

>>10
You Javelly?

That's a joke we have here at Oracle, it's Enterprise quality though, so you wouldn't understand it.

Name: Anonymous 2011-12-20 20:01

>>8
That shit is why markdown was invented.

Name: Anonymous 2011-12-26 5:40

>>6,8
Bump for enterprise quality commenting.

Newer Posts
Don't change these.
Name: Email:
Entire Thread Thread List