JSPinner and floating point quirk

Please test these spinners only with their down arrow buttons to reach minimum value of each. When the number of fraction columns are 5,10 and 12, spinner stops at one step before the real minimum. They don't go to the real minimum. Why could this happen?
import javax.swing.*;
import java.text.*;
public class SpinnerQuirk{
  public static void main(String[] args){
    Box panel = new Box(BoxLayout.X_AXIS);
    double fraction = 0.01;
    double base = 1.0;
    String fmt = "#0.00";
    for (int i = 2; i < 14; ++i){
      DecimalFormat df = new DecimalFormat(fmt);
      Box box = new Box(BoxLayout.Y_AXIS);
      JSpinner spinner = new JSpinner();
      SpinnerNumberModel spinnerModel
        = new SpinnerNumberModel(base + fraction,
                                 base + fraction - fraction * 101,
                                 base + fraction + fraction * 99,
                                 fraction);
      spinner.setModel(spinnerModel);
      spinner.setEditor(new JSpinner.NumberEditor(spinner, fmt));
      JLabel label = new JLabel("min = "
          + df.format((base + fraction - fraction * 101)));
      box.add(spinner);
      box.add(label);
      panel.add(box);
      fraction = fraction / 10.0;
      fmt += "0";
    JOptionPane.showMessageDialog(null, panel);
    System.exit(0);
}

Thanks. I think I have found the root cause of the problem. That is, there's no effective communications between java.text formatting and javax.swing.text one(*). A bad example of a bureaucratic sectionalism at Sun?
(*: Because DecimalFormat does the right job given the same format string and same value.)
Japanese: tate wari
Englisn: divided vertically
Edited by: hiwa on Oct 5, 2007 11:18 AM

Similar Messages

  • Pack  and Floating Point Data Type in ABAP

    Dear All,
    I am new to ABAP. Started with data types. Came across pack and floating point.
    Please let me know what PACK  and Floating Point stands for with few examples and the main difference between them.
    Regards
    Arun V

    Hi,
    You'd better ask this question in ABAP forum http://forums.sdn.sap.com/forum.jspa?forumID=50 .
    Best Regards,
    Ada

  • Precision loss - conversions between exact values and floating point values

    Hi!
    I read this in your SQL Reference manual, but I don't quite get it.
    Conversions between exact numeric values (TT_TINYINT, TT_SMALLINT, TT_INTEGER, TT_BIGINT, NUMBER) and floating-point values (BINARY_FLOAT, BINARY_DOUBLE) can be inexact because the exact numeric values use decimal precision whereas the floating-point numbers use binary precision.
    Could you please give two examples: one where a TT_TINYINT is converted to a BINARY_DOUBLE and one when a TT_BIGINT is converted into a DOUBLE, both cases give examples on lost precision? This would be very helpful.
    Thanks!
    Sune

    chokpa wrote:
    Public Example (float... values){}
    new Example (1, 1e2, 3.0, 4.754);It accepts it if I just use 1,2,3,4 as the values being passed in, but doesn't like it if I use actual float values.Those are double literals, try
    new Example (1f, 1e2f, 3.0f, 4.754f);

  • What does Little Endian and Floating Point actually do?

    Exporting audio to video using Linear PCM format brings along two mysterios options called "Little Endian" and "Floating Point". I did my research but all I could dig out was that the first one, Little Endian, has to do with addressing subcomponents of a file etc.
    Does anyone know what these two actually mean in terms of exporting audio and why do I only see them in logic and not in Protools for example?
    Thanks...

    Big Endian is most significant byte (bit) first, Little Endian is most significant byte (bit) last. When we write down a number, we use big endian: one million threehundred and twentyfivethousand ninehundred and fiftyfour we'd write as 1 325 954. in little endian notation that would be 459 523 1.
    I don't know why they show up when exporting audio to video, maybe it is to adaprt the audio to some other (older?) formats?

  • SQL Loader and Floating Point Numbers

    Hi
    I have a problem loading floating point numbers using SQL Loader. If the number has more than 8 significant digits SQL Loader rounds the number i.e. 1100000.69 becomes 1100000.7. The CTL file looks as follows
    LOAD DATA
    INFILE '../data/test.csv' "str X'0A'"
    BADFILE '../bad/test.bad'
    APPEND
    INTO TABLE test
    FIELDS TERMINATED BY "," OPTIONALLY ENCLOSED BY '"'
    Amount CHAR
    and the data file as follows
    "100.15 "
    "100100.57 "
    "1100000.69 "
    "-2000000.33"
    "-100000.43 "
    the table defined as follows
    CREATE TABLE test
    Amount number(15,4)
    ) TABLESPACE NNUT050M1;
    after loading a select returns the following
    100.15
    100100.57
    1100000.7
    -2000000
    -100000.4
    Thanks in advance
    Russell

    Actually if you format the field to display as (say) 999,999,999.99, you will see the correct numbers loaded via SQL Loader.
    null

  • Inline functions in C, gcc optimization and floating point arithmetic issues

    For several days I really have become a fan of Alchemy. But after intensive testing I have found several issues which I'd like to solve but I can't without any help.
    So...I'm porting an old game console emulator written by me in ANSI C. The code is working on both gcc and VisualStudio without any modification or crosscompile macros. The only platform code is the audio and video output which is out of scope, because I have ported audio and video witin AS3.
    Here are the issues:
    1. Inline functions - Having only a single inline function makes the code working incorrectly (although not crashing) even if any optimization is enabled or not (-O0 or O3). My current workarround is converting the inline functions to macros which achieves the same effect. Any ideas why inline functions break the code?
    2. Compiler optimizations - well, my project consists of many C files one of which is called flash.c and it contains the main and exported functions. I build the project as follows:
    gcc -c flash.c -O0 -o flash.o     //Please note the -O0 option!!!
    gcc -c file1.c -O3 -o file1.o
    gcc -c file2.c -O3 -o file2.o
    ... and so on
    gcc *.o -swc -O0 -o emu.swc   //Please note the -O0 option again!!!
    mxmlc.exe -library-path+=emu.swc --target-player=10.0.0 Emu.as
    or file in $( ls *.o ) //Removes the obj files
        do
            rm $file
        done
    If I define any option different from -O0 in gcc -c flash.c -O0 -o flash.o the program stops working correctly exactly as in the inline funtions code (but still does not crash or prints any errors in debug). flash has 4 static functions to be exported to AS3 and the main function. Do you know why?
    If I define any option different from -O0 in gcc *.o -swc -O0 -o emu.swc  the program stops working correctly exactly as above, but if I specify -O1, -O2 or O3 the SWC file gets smaller up to 2x for O3. Why? Is there a method to optimize all the obj files except flash.o because I suspect a similar issue as when compilling it?
    3. Flating point issues - this is the worst one. My code is mainly based on integer arithmetic but on 1-2 places it requires flating point arithmetic. One of them is the conversion of 16-bit 44.1 Khz sound buffer to a float buffer with same sample rate but with samples in the range from -1.0 to 1.0.
    My code:
    void audio_prepare_as()
        uint32 i;
        for(i=0;i<audioSamples;i+=2)
            audiobuffer[i] = (float)snd.buffer[i]/32768;
            audiobuffer[i+1] = (float)snd.buffer[i+1]/32768;
    My audio playback is working perfectly. But not if using the above conversion and I have inspected the float numbers - all incorrect and invalid. I tried other code with simple floats - same story. As if alchemy refuses to work with floats. What is wrong? I have another lace whre I must resize the framebuffer and there I have a float involved - same crap. Please help me?
    Found the floating point problem: audiobuffer is written to a ByteArray and then used in AS. But C floats are obviously not the same as those in AS3. Now the floating point is resolved.
    The optimization issues remain! I really need to speed up my code.
    Thank you in advice!

    Dear Bernd,
    I am still unable to run the optimizations and turn on the inline functions. None of the inline functions contain any stdli function just pure asignments, reads, simple arithmetic and bitwise operations.
    In fact, the file containing the main function and those functions for export in AS3 did have memset and memcpy. I tried your suggestion and put the code above the functions calling memset and memcpy. It did not work soe I put the code in a header which is included topmost in each C file. The only system header I use is malloc.h and it is included topmost. In other C file I use pow, sin and log10 from math.h but I removed it and made the same thing:
    //shared.h
    #ifndef _SHARED_H_
    #define _SHARED_H_
    #include <malloc.h>
    static void * custom_memmove( void * destination, const void * source, unsigned int num ) {
      void *result; 
      __asm__("%0 memmove(%1, %2, %3)\n" : "=r"(result) : "r"(destination), "r"(source), "r"(num)); 
      return result; 
    static void * custom_memcpy ( void * destination, const void * source, unsigned int num ) { 
      void *result; 
      __asm__("%0 memcpy(%1, %2, %3)\n" : "=r"(result) : "r"(destination), "r"(source), "r"(num)); 
      return result; 
    static void * custom_memset ( void * ptr, int value, unsigned int num ) { 
      void *result; 
      __asm__("%0 memset(%1, %2, %3)\n" : "=r"(result) : "r"(ptr), "r"(value), "r"(num)); 
      return result; 
    static float custom_pow(float x, int y) {
        float result;
      __asm__("%0 pow(%1, %2)\n" : "=r"(result) : "r"(x), "r"(y));
      return result;
    static double custom_sin(double x) {
        double result;
      __asm__("%0 sin(%1)\n" : "=r"(result) : "r"(x));
      return result;
    static double custom_log10(double x) {
        double result;
      __asm__("%0 log10(%1)\n" : "=r"(result) : "r"(x));
      return result;
    #define memmove custom_memmove
    #define memcpy custom_memcpy
    #define memset custom_memset
    #define pow custom_pow
    #define sin custom_sin
    #define log10 custom_log10 
    #include "types.h"
    #include "macros.h"
    #include "m68k.h"
    #include "z80.h"
    #include "genesis.h"
    #include "vdp.h"
    #include "render.h"
    #include "mem68k.h"
    #include "memz80.h"
    #include "membnk.h"
    #include "memvdp.h"
    #include "system.h"
    #include "loadrom.h"
    #include "input.h"
    #include "io.h"
    #include "sound.h"
    #include "fm.h"
    #include "sn76496.h" 
    #endif /* _SHARED_H_ */ 
    It still behave the same way as if nothing was changed (works incorrectly - displays jerk which does not move, whereby the image is supposed to move)
    As I am porting an emulator (Sega Mega Drive) I use manu arrays of function pointers for implementing the opcodes of the CPU's. Could this be an issue?
    I did a workaround for the floating point problem but processing is very slow so I hear only bzzt bzzt but this is for now out of scope. The emulator compiled with gcc runs at 300 fps on a 1.3 GHz machine, whereby my non optimized AVM2 code compiled by alchemy produces 14 fps. The pure rendering is super fast and the problem lies in the computational power of AVM. The frame buffer and the enulation are generated in the C code and only the pixels are copied to AS3, where they are plotted in a BitmapData. On 2.0 GHz Dual core I achieved only 21 fps. Goal is 60 fps to have smooth audio and video. But this is offtopic. After all everything works (slow) without optimization, and I would somehow turn it on. Suggestions?
    Here is the file with the main function:
    #include "shared.h"
    #include "AS3.h"
    #define FRAMEBUFFER_LENGTH    (320*240*4)
    static uint8* framebuffer;
    static uint32  audioSamples;
    AS3_Val sega_rom(void* self, AS3_Val args)
        int size, offset, i;
        uint8 hardware;
        uint8 country;
        uint8 header[0x200];
        uint8 *ptr;
        AS3_Val length;
        AS3_Val ba;
        AS3_ArrayValue(args, "AS3ValType", &ba);
        country = 0;
        offset = 0;
        length = AS3_GetS(ba, "length");
        size = AS3_IntValue(length);
        ptr = (uint8*)malloc(size);
        AS3_SetS(ba, "position", AS3_Int(0));
        AS3_ByteArray_readBytes(ptr, ba, size);
        //FILE* f = fopen("boris_dump.bin", "wb");
        //fwrite(ptr, size, 1, f);
        //fclose(f);
        if((size / 512) & 1)
            size -= 512;
            offset += 512;
            memcpy(header, ptr, 512);
            for(i = 0; i < (size / 0x4000); i += 1)
                deinterleave_block(ptr + offset + (i * 0x4000));
        memset(cart_rom, 0, 0x400000);
        if(size > 0x400000) size = 0x400000;
        memcpy(cart_rom, ptr + offset, size);
        /* Free allocated file data */
        free(ptr);
        hardware = 0;
        for (i = 0x1f0; i < 0x1ff; i++)
            switch (cart_rom[i]) {
         case 'U':
             hardware |= 4;
             break;
         case 'J':
             hardware |= 1;
             break;
         case 'E':
             hardware |= 8;
             break;
        if (cart_rom[0x1f0] >= '1' && cart_rom[0x1f0] <= '9') {
            hardware = cart_rom[0x1f0] - '0';
        } else if (cart_rom[0x1f0] >= 'A' && cart_rom[0x1f0] <= 'F') {
            hardware = cart_rom[0x1f0] - 'A' + 10;
        if (country) hardware=country; //simple autodetect override
        //From PicoDrive
        if (hardware&8)        
            hw=0xc0; vdp_pal=1;
        } // Europe
        else if (hardware&4)    
            hw=0x80; vdp_pal=0;
        } // USA
        else if (hardware&2)    
            hw=0x40; vdp_pal=1;
        } // Japan PAL
        else if (hardware&1)      
            hw=0x00; vdp_pal=0;
        } // Japan NTSC
        else
            hw=0x80; // USA
        if (vdp_pal) {
            vdp_rate = 50;
            lines_per_frame = 312;
        } else {
            vdp_rate = 60;
            lines_per_frame = 262;
        /*SRAM*/   
        if(cart_rom[0x1b1] == 'A' && cart_rom[0x1b0] == 'R')
            save_start = cart_rom[0x1b4] << 24 | cart_rom[0x1b5] << 16 |
                cart_rom[0x1b6] << 8  | cart_rom[0x1b7] << 0;
            save_len = cart_rom[0x1b8] << 24 | cart_rom[0x1b9] << 16 |
                cart_rom[0x1ba] << 8  | cart_rom[0x1bb] << 0;
            // Make sure start is even, end is odd, for alignment
            // A ROM that I came across had the start and end bytes of
            // the save ram the same and wouldn't work.  Fix this as seen
            // fit, I know it could probably use some work. [PKH]
            if(save_start != save_len)
                if(save_start & 1) --save_start;
                if(!(save_len & 1)) ++save_len;
                save_len -= (save_start - 1);
                saveram = (unsigned char*)malloc(save_len);
                // If save RAM does not overlap main ROM, set it active by default since
                // a few games can't manage to properly switch it on/off.
                if(save_start >= (unsigned)size)
                    save_active = 1;
            else
                save_start = save_len = 0;
                saveram = NULL;
        else
            save_start = save_len = 0;
            saveram = NULL;
        return AS3_Int(0);
    AS3_Val sega_init(void* self, AS3_Val args)
        system_init();
        audioSamples = (44100 / vdp_rate)*2;
        framebuffer = (uint8*)malloc(FRAMEBUFFER_LENGTH);
        return AS3_Int(vdp_rate);
    AS3_Val sega_reset(void* self, AS3_Val args)
        system_reset();
        return AS3_Int(0);
    AS3_Val sega_frame(void* self, AS3_Val args)
        uint32 width;
        uint32 height;
        uint32 x, y;
        uint32 di, si, r;
        uint16 p;
        AS3_Val fb_ba;
        AS3_ArrayValue(args, "AS3ValType", &fb_ba);
        system_frame(0);
        AS3_SetS(fb_ba, "position", AS3_Int(0));
        width = (reg[12] & 1) ? 320 : 256;
        height = (reg[1] & 8) ? 240 : 224;
        for(y=0;y<240;y++)
            for(x=0;x<320;x++)
                di = 1280*y + x<<2;
                si = (y << 10) + ((x + bitmap.viewport.x) << 1);
                p = *((uint16*)(bitmap.data + si));
                framebuffer[di + 3] = (uint8)((p & 0x1f) << 3);
                framebuffer[di + 2] = (uint8)(((p >> 5) & 0x1f) << 3);
                framebuffer[di + 1] = (uint8)(((p >> 10) & 0x1f) << 3);
        AS3_ByteArray_writeBytes(fb_ba, framebuffer, FRAMEBUFFER_LENGTH);
        AS3_SetS(fb_ba, "position", AS3_Int(0));
        r = (width << 16) | height;
        return AS3_Int(r);
    AS3_Val sega_audio(void* self, AS3_Val args)
        AS3_Val ab_ba;
        AS3_ArrayValue(args, "AS3ValType", &ab_ba);
        AS3_SetS(ab_ba, "position", AS3_Int(0));
        AS3_ByteArray_writeBytes(ab_ba, snd.buffer, audioSamples*sizeof(int16));
        AS3_SetS(ab_ba, "position", AS3_Int(0));
        return AS3_Int(0);
    int main()
        AS3_Val romMethod = AS3_Function(NULL, sega_rom);
        AS3_Val initMethod = AS3_Function(NULL, sega_init);
        AS3_Val resetMethod = AS3_Function(NULL, sega_reset);
        AS3_Val frameMethod = AS3_Function(NULL, sega_frame);
        AS3_Val audioMethod = AS3_Function(NULL, sega_audio);
        // construct an object that holds references to the functions
        AS3_Val result = AS3_Object("sega_rom: AS3ValType, sega_init: AS3ValType, sega_reset: AS3ValType, sega_frame: AS3ValType, sega_audio: AS3ValType",
            romMethod, initMethod, resetMethod, frameMethod, audioMethod);
        // Release
        AS3_Release(romMethod);
        AS3_Release(initMethod);
        AS3_Release(resetMethod);
        AS3_Release(frameMethod);
        AS3_Release(audioMethod);
        // notify that we initialized -- THIS DOES NOT RETURN!
        AS3_LibInit(result);
        // should never get here!
        return 0;

  • [Solved] Bash and Floating point arithmetic

    I didn't realize how troublesome floating point numbers can be until now.
    What I want to do should be simple I dare say:
    properRounding( ( currentTime - downloadTime ) / ( dueTime - downloadTime ) * 100 )
    however best I've been able to achieve so far is this:
    echo "($currentTime-$downloadTime)/($dueTime-$downloadTime)*100" | bc -l
    Which prints the correct floating point value.
    I've tried to put the result in a variable, but I must be doing it wrong as I get the most peculiar error. I can live without it, but it would make life easier.
    As for the rounding, that is a must. I've read that if you remove the -l param from bc, then it will round, but in my case something goes wrong as I just get the value 0 in return and besides, concluded after a simple test, bc always rounds down as in integer division, which I can not use.
    So of course I'll continue reading and hopefully someday arrive at a solution, but I would very much appreciate if someone could lend me a hand.
    This after all is not just a learning experience, I'm trying to create something useful.
    Best regards.
    edit:
    nb:
    all variables are integers.
    Last edited by zacariaz (2012-09-09 14:50:18)

    Just for the fun of it, here's my progress thus far... Well, there really isn't much more to do. The rest is a conky thing.
    #!/bin/bash
    # Variables from unitinfo.txt - date as unix timestamps.
    dueTime="$(date +%s -d "$(grep 'Due time: ' ~/unitinfo.txt | cut -c11-)")"
    if [ "$1" = "end" ]
    then echo $dueTime
    fi
    downloadTime="$(date +%s -d "$(grep 'Download time: ' ~/unitinfo.txt | cut -c16-)")"
    if [ "$1" = "start" ]
    then echo $downloadTime
    fi
    progress="$(grep 'Progress: ' ~/unitinfo.txt | cut -c11-12 | sed 's/ *$//')"
    if [ "$1" = "prog1" ]
    then echo $progress
    fi
    # The rest
    #progress valued 0-1 for use with conky proress bars
    progress2=$( echo 2k $progress 100 / f | dc )
    if [ "$1" = "prog2" ]
    then echo $progress2
    fi
    # Current time - unix timestamp.
    currentTime="$(date +%s)"
    # Remaining time - unix timestamp
    remainingTime=$(( dueTime-$currentTime ))
    if [ "$1" = "remain" ]
    then echo $remainingTime
    fi
    # Elapsed time - unix timestamp
    elapsedTime=$(( currentTime-downloadTime ))
    if [ "$1" = "elap1" ]
    then echo $elapsedTime
    fi
    # Total amount of time available - unix timestamp
    totalTime=$(( dueTime-downloadTime ))
    if [ "$1" = "total" ]
    then echo $totalTime
    fi
    # How much time has elapsed in percent
    progress3="$(echo 3k $elapsedTime $totalTime / 100 \* 0k 0.5 + 1 / f | dc)"
    if [ "$1" = "elap2" ]
    then echo $progress3
    fi
    # Like the above bur 0-1
    progress4=$( echo 2k $progress3 100 / f | dc )
    if [ "$1" = "elap3" ]
    then echo $progress4
    fi
    # In percent, expected completion vs $dueTime - less than 100 is better.
    expectedCompletion="$( echo 3k $elapsedTime 10000 \* $progress / $totalTime / 0k 0.5 + 1 / f | dc )"
    if [ "$1" = "exp1" ]
    then echo $expectedCompletion
    fi
    # Same as above, but unix timestamp
    expectedCompletion2=$(( downloadTime+(expectedCompletion*totalTime/100) ))
    if [ "$1" = "exp2" ]
    then echo $expectedCompletion2
    fi
    #efficiency
    if [ "$1" = "ef1" ]; then
    if [ $progress -lt $progress3 ]
    then echo "you're behind schedule."
    elif [ $progress -eq $progress3 ]
    then echo "You're right on schedule."
    else
    echo "You're ahead of schedule."
    fi
    fi
    if [ "$1" = "ef2" ]; then
    if [ $expectedCompletion -gt 100 ]
    then echo "You're not going to make it!"
    else
    echo "You're going to make it!"
    fi
    fi

  • MIDP and floating-point numbers

    Hiya,
    I need to use floating numbers in a few occasions in a MIDP app that I'm programming at the moment. Whenever I do so though I get a nervous-breaking error at the pre-verification stage of the build. I am working with Wireless Toolkit 2.0 and the rror I get is:
    Building "MyMIDlet"
    Error preverifying class <ClassName>
    ERROR: floating-point constants should not appear
    com.sun.kvem.ktools.ExecutionException: Preverifier returned 1
    Build failedI get this error whenever I use a floating-point varible or even whenever I compare something to a floating-point value.
    It's got me really puzzled and I can't think of any way around the problem. Any help would be very much appreciated...
    Thanks!

    also WTK 2.1 (and CLDC 1.1I think ) does support FP. You think right, CLDC 1.1, that's when they added the floats (in theory a device could be MIDP 1.0 on top of CLDC 1.1, and it would also have floats). There's only one CLDC 1.1 device I've heard of: Nokia 6320.
    shmoove

  • Floating point formats: Java/C/C++, PPC and Intel platforms

    Hi everyone
    Where can I find out about the various bit formats used for 32 bit floating numbers in Java and C/C++ for both Mac hardware platforms?
    I'm developing a Java audio application which needs to convert vast quantities of variable width integer audio samples to canonical float audio format. I've discovered that a floating point divide by the maximum integer value gives the correct answer but takes too much processor time, so I'm trying out bit-twiddling in C via JNI to carve out my own floating point bit patterns. This is very fast, however, I need to take into account the various float formats used on the different platforms so my app can be universal. Can anyone point me to the information?
    Thanks in advance.
    Bob

    I am not sure that Rosetta floating point works the same as PPC floating point. I was using RealBasic (a PPC basic compiler) and moved one of the my compiled applications to a MacBook Pro and floating point comparisons that had been exact on the PPC stopped working under Rosetta. I changed the code to do an approximate comparison (i.e. abs(a -b) < tolerance) and this fixed things.
    I reported the problem to the RealBasic people and thought nothing more of it until I fired up Adobe's InDesign and not being used to working with picas, changed the units of measurement to inches. The default letter paper size was suddenly 8.5000500050005 inches instead of the more usual 8.5! This was not a big problem, but it appears that all of InDesign's page math is running into some kind of rounding errors.
    The floating point format is almost certainly IEEE, and I cannot imagine Rosetta doing anything other than using native hardware Intel floating point. On the other hand, there is a subtle difference in behavior.
    I am posting this here as a follow up, but I am also going to post this as a proper question in the forum. If you have to delete one or the other of these duplicate posts, please zap the reply, not the question.

  • Number and Float  column size

    What's the size limitation on the NUMBER type column, how many digits it can be?
    I need to convert the data in the column to a byte array and I need to decide how long the byte array shoud be before hand.
    Also, I need the same info for a FLOAT type column.
    Can someone help me with it? Thanks.

    see
    http://technet.oracle.com/docs/products/oracle8i/doc_library/817_doc/server.817/a85397/sql_elem.htm#45443
    Excerpt from the document:
    NUMBER Datatype
    The NUMBER datatype stores zero, positive, and negative fixed and floating-point numbers with magnitudes between 1.0 x 10^-130 and 9.9...9 x 10^125 (38 nines followed by 88 zeroes) with 38 digits of precision. If you specify an arithmetic expression whose value has a magnitude greater than or equal to 1.0 x 10^126, Oracle returns an error.

  • Passing floating point values, but being recognised as doubles and int's?

    Hi,
    I was wondering how to differentiate between floating point values and ints etc
    I am passing values into a public class with the parameters (float... values)
    Public Example (float... values){}new Example (1, 1e2, 3.0, 4.754);
    It accepts it if I just use 1,2,3,4 as the values being passed in, but doesn't like it if I use actual float values.
    How come?
    Cheers

    chokpa wrote:
    Public Example (float... values){}
    new Example (1, 1e2, 3.0, 4.754);It accepts it if I just use 1,2,3,4 as the values being passed in, but doesn't like it if I use actual float values.Those are double literals, try
    new Example (1f, 1e2f, 3.0f, 4.754f);

  • Inconsistent Floating Point Math and NaNs on Windows Laptops?

    All -
    I am seeing some very strange inconsistent floating point calculations on Windows Laptops, and I am wondering if anyone has any ideas. Read on, as (to me!) it's very interesting....
    I have attached a segment of our code, along with some sample output. Looking at the code and the output, it seems like it's totally impossible.
    With supposedly non-NaN and non-infinite double values, I am seeing unrepeatable and inconsistent math - the below example only illustrates one such case where we're seeing this behavior.
    If you look at the code below, you will see that I do things like:
    double rhoYo = ...  // some math
    double rho = ...  // exact same mathStrangely enough, I might get rhoYo = 1.51231231 etc and rho = NaN.
    If I reverse those lines (vertically), then again, rhoYo comes out good and rho comes out NaN; however, this is unpredictable and inconsistent. If I project a source point, get a destination point with NaNs as a result, and project the source again, the second destination point may be just fine. Matter of fact, i can put a loop in the code such as:
          double rho = Double.NaN;
          for( int i = 0; i < 10; i++ )
            rho = my_earthRad * my_F / Math.pow(Math.tan(Math.PI/4.0 + latRad/2.0), my_n);
            if( ! Double.isNaN( rho ) )
              break;
            System.out.println("NaN'ed rho");
          }and rho will eventually become non-NaN (random # of iterations)!!
    How's that possible? Our code might be tromping on memory somewhere, but this sure seems crazy to me, especially considering that
    we're only using local variables. Anyone know of floating point errors on Windows Laptops?
    With the exact same codebase, this behavior ONLY happens on Windows Laptops, including brand new Dells, old Dells, IBM, Intel and AMD chips (I've tried several ;-). It does NOT happen on Mac or Linux, including the Linux side of a Linux/Windows dual-boot (where it does happen with the Windows side). Even more strangely, it does NOT happen with Windows desktops. I have tried several 1.5.x JVMs, webstart vs no webstart, etc, to no avail. Always and only on Windows Laptops.
    Please help.... ;-) and thanks in advance.
    Sample code:
    public class Projection
      protected Point2D.Double _project(Point2D.Double srcPt, Point2D.Double dstPt) {
        final double my_degToRad = Math.PI / 180.0;
        final double my_originLon = -95.0;
        final double my_originLonRad = my_originLon * my_degToRad;
        final double my_originLat = 25.0;
        final double my_originLatRad = my_originLat * my_degToRad;;
        final double my_stdLat1 = 25.0;
        final double my_stdLat1Rad = my_stdLat1 * my_degToRad;
        final double my_earthRad = 6371.2;
        final double my_n = Math.sin( my_stdLat1Rad );
        final double my_F = Math.cos( my_stdLat1Rad ) * Math.pow( Math.tan( Math.PI / 4.0 + my_stdLat1Rad / 2.0 ), my_n ) / my_n;
        final double my_rhoZero = my_earthRad * my_F / Math.pow( Math.tan( Math.PI / 4.0 + my_originLatRad / 2.0 ), my_n );
        if ( Double.isNaN( my_n ) || Double.isNaN( my_F ) || Double.isNaN( my_rhoZero )) {
          return new Point2D.Double(Double.NaN, Double.NaN);
        if( Double.isNaN( srcPt.x ) || Double.isNaN( srcPt.y ) )
            System.out.println("======= _project received a srcPt with NaNs. Returning NaN point.");
            Point2D.Double nanPoint = new Point2D.Double();
            nanPoint.x = nanPoint.y = Double.NaN;
            return nanPoint;
        if( Double.isInfinite( srcPt.x ) || Double.isInfinite( srcPt.y ) )
            System.out.println("======= _project received a srcPt with isInfinite. Returning NaN point.");
            Point2D.Double nanPoint = new Point2D.Double();
            nanPoint.x = nanPoint.y = Double.NaN;
            return nanPoint;
        //  Inputs are lon, lat degrees.
        final double lonRad = srcPt.x * my_degToRad;
        final double latRad = srcPt.y * my_degToRad;
        final double theta = my_n * (lonRad - my_originLonRad);
        // One Std lat -- tangential cone.
        final double rhoYo = my_earthRad * my_F / Math.pow(Math.tan(Math.PI/4.0 + latRad/2.0), my_n);
        final double rho   = my_earthRad * my_F / Math.pow(Math.tan(Math.PI/4.0 + latRad/2.0), my_n);
        // Computes kilometers in lambert space.
        dstPt.x = rho * Math.sin(theta);
        dstPt.y = my_rhoZero - (rho * Math.cos(theta));
        // WANK - Here's the problem!  These values shouldnt be NaN!
        if( Double.isNaN( dstPt.x ) || Double.isNaN( dstPt.y ) )
            System.out.println("======= A _projected dstPt has NaNs. Dumping...vvvvvvvvvvvvvvvvvvvvvvvvvvvv");
            if( Double.isNaN( dstPt.x ) )
                System.out.println("======= dstPt.x is NaN");
            if( Double.isNaN( dstPt.y ) )
                System.out.println("======= dstPt.y is NaN");
            System.out.println("======= my_stdLat1 = " + my_stdLat1 );
            System.out.println("======= my_n = " + my_n );
            System.out.println("======= my_originLonRad = " + my_originLonRad );
            System.out.println("======= my_F = " + my_F );
            System.out.println("======= my_earthRad = " + my_earthRad );
            System.out.println("======= lonRad = " + lonRad );
            System.out.println("======= latRad = " + latRad );
            System.out.println("======= theta = " + theta );
            System.out.println("======= Math.tan(Math.PI/4.0 + latRad/2.0) = " + Math.tan(Math.PI/4.0 + latRad/2.0) );
            System.out.println("======= Math.pow(Math.tan(Math.PI/4.0 + latRad/2.0), my_n) = " + Math.pow(Math.tan(Math.PI/4.0 + latRad/2.0), my_n) );
            System.out.println("======= rho = " + rho );
            System.out.println("======= rhoYo = " + rhoYo );
            System.out.println("======= Math.sin(theta) = " + Math.sin(theta) );
            System.out.println("======= dstPt.x = " + dstPt.x );
            System.out.println("======= Math.cos(theta) = " + Math.cos(theta) );
            System.out.println("======= my_rhoZero = " + my_rhoZero );
            System.out.println("======= (rhoYo * Math.cos(theta)) = " + (rho * Math.cos(theta)) );
            System.out.println("======= my_rhoZero - (rhoYo * Math.cos(theta)) = " + (my_rhoZero - (rho * Math.cos(theta)) ));
            System.out.println("======= dstPt.y = " + dstPt.y );
            System.out.println("======= A _projected dstPt had NaNs. Done dumping. ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^");
        return dstPt;
    }And here's the sample output:
    ======= A _projected dstPt has NaNs. Dumping...vvvvvvvvvvvvvvvvvvvvvvvvvvvv
    ======= dstPt.x is NaN
    ======= dstPt.y is NaN
    ======= my_stdLat1 = 25.0
    ======= my_n = 0.42261826174069944
    ======= my_originLonRad = -1.6580627893946132
    ======= my_F = 2.5946660025799146
    ======= my_earthRad = 6371.2
    ======= lonRad = -2.7564670759053924
    ======= latRad = 0.3730758324037379
    ======= theta = -0.4642057102537187
    ======= Math.tan(Math.PI/4.0 + latRad/2.0) = 1.4652768116539785
    ======= Math.pow(Math.tan(Math.PI/4.0 + latRad/2.0), my_n) = 1.175224090766834
    ======= rho = NaN
    ======= rhoYo = 14066.369269924155
    ======= Math.sin(theta) = -0.44771270676160557
    ======= dstPt.x = NaN
    ======= Math.cos(theta) = 0.8941774612481554
    ======= my_rhoZero = 13663.082491950498
    ======= (rhoYo * Math.cos(theta)) = NaN
    ======= my_rhoZero - (rhoYo * Math.cos(theta)) = NaN
    ======= dstPt.y = NaN
    ======= A _projected dstPt had NaNs. Done dumping. ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

    HI JSchell (and others?) -
    I have created a simple example attached below, that when run repeatedly, does indeed generate spurious NaNs. I have made it as simple as possible. In the code, I use my own lon/lat binary data file, though I am sure any will do. Let me know if anyone wants that file.
    So the deal is that (with my data at least) this program should never generate NaN results. And if one runs it 25432 (eg: random #) times, it wont, but then the 25433th time, it will create NaNs, etc. ie: inconsistent NaN math results.
    As I said before, I have run this on old and new Dell laptops under Windows XP, using java 1.5_02, 1.5_04 and 1.5_08. The latest run was on a brand new Dell with a Intel Core Duo T2600 processor, running XP. If this is a result of the Pentium bug, one would think that would be fixed by now. I have NOT yet tested on AMD, though I will do that this afternoon.
    Remember, this ONLY happens with Windows Laptops.
    Any ideas anyone? Thanks in advance ;-)
    Here's the code that produces spurious NaNs:
    import java.awt.geom.Point2D;
    import java.io.DataInputStream;
    import java.io.EOFException;
    import java.io.File;
    import java.io.FileInputStream;
    public class FloatingPointTest2 implements Runnable
      private static final int NUM_ITERATIONS = 100000;
      private double _degToRad = Math.PI / 180.0;
      private double _originLon = -95.0;
      private double _originLat = 25.0;
      private double _originLonRad = _originLon * _degToRad;
      private double _originLatRad = _originLat * _degToRad;;
      private double _stdLat1 = 25.0;
      private double _stdLat1Rad = _stdLat1 * _degToRad;
      private double _earthRad = 6371.2;
      private double _n = _n = Math.sin( _stdLat1Rad );
      private double _F = Math.cos( _stdLat1Rad ) * Math.pow( Math.tan( Math.PI / 4.0 + _stdLat1Rad / 2.0 ), _n ) / _n;
      private double _rhoZero = _earthRad * _F / Math.pow( Math.tan( Math.PI / 4.0 + _originLatRad / 2.0 ), _n );
      private Point2D.Double _project( Point2D.Double srcPt, Point2D.Double dstPt )
        if( Double.isNaN( srcPt.x ) || Double.isNaN( srcPt.y ) )
          System.out.println( "FloatingPointTest2: received a NaN srcPt.  Skipping." );
          return new Point2D.Double( Double.NaN, Double.NaN );
        //  Inputs are lon, lat degrees.
        final double lonRad = srcPt.x * _degToRad;
        final double latRad = srcPt.y * _degToRad;
        final double theta = _n * ( lonRad - _originLonRad );
        double rho = _earthRad * _F / Math.pow( Math.tan( Math.PI / 4.0 + latRad / 2.0 ), _n );
        dstPt.x = rho * Math.sin( theta );
        dstPt.y = _rhoZero - ( rho * Math.cos( theta ) );
        return dstPt;
      public void doTest()
        DataInputStream instream = null;
        int thisRunNaNCount = 0;
        Point2D.Double tempPt = new Point2D.Double();
        Point2D.Double dstPt = new Point2D.Double();
        try
          instream = new DataInputStream( new FileInputStream( System.getProperty(
            "user.home" ) + File.separatorChar + "lonLatBinaryData.bin" ) );
          try
            while( true )
              double lon = instream.readDouble();
              double lat = instream.readDouble();
              if( Double.isNaN( lon ) || Double.isNaN( lat ) )
                continue;
              tempPt.x = lon;
              tempPt.y = lat;
              dstPt = _project( tempPt, dstPt );
              if( Double.isNaN( dstPt.x ) || Double.isNaN( dstPt.y ) )
                thisRunNaNCount++;
          catch( EOFException e )
    //        System.out.println( "End of file" );
          if( thisRunNaNCount > 0 )
            System.out.println( "thisRunNaNCount = " + thisRunNaNCount );
          instream.close();
        catch( Exception e )
          e.printStackTrace();
          System.exit( 1 );
      public void run()
        doTest();
      public static void main( String args[] )
        System.out.println( "Executing FloatingPointTest2." );
        for( int i = 0; i < NUM_ITERATIONS; i++ )
          FloatingPointTest2 test = new FloatingPointTest2();
          test.doTest();
    }

  • JSpinner and small values

    This code don't works properly
    spinner.setModel(new SpinnerNumberModel(3.0,null,null,0.1));This is the JSpinner but the number displayed in the included JTextField don't represent the correct value.
    For example, in some case the number displayed is 3.3 but the number that returns spinner.getValue() is 3.30000000003.
    I want that spinner.getValue returns 3.3
    There is a solution to this problem?

    Ayrton_4 wrote:
    This code don't works properly
    spinner.setModel(new SpinnerNumberModel(3.0,null,null,0.1));This is the JSpinner but the number displayed in the included JTextField don't represent the correct value.
    For example, in some case the number displayed is 3.3 but the number that returns spinner.getValue() is 3.30000000003.
    I want that spinner.getValue returns 3.3
    There is a solution to this problem?Yes, you need desperately to learn about how all computers treat floating point numbers and work your programs accordingly. 3.30000000003 is a reasonable representation of 3.3 when working with floating point numbers. The key here is how to display this number correctly, and for this I often use the String.format( ) method which is similar to c's printf.
    Please read in the tutorial section the parts about floating point math and you will understand.

  • R6002 - floating point not loaded / C++ Runtime Error

    Good Evening,
    I have been having this problem with Adobe Bridge for a while and tonight sat down to try and solve it. Fresh version of Windows XP reinstalled all programs and this is still happening! Any Ideas?
    This error only occurs with Adobe Bridge, I can load Photoshop etc.. all fine.
    Error:
    "Runtime Error!
    Program: C:\ProgramFiles\Adobe\Adobe Bridge CS3\Bridge.exe
    R6002
    - floating point not loaded"
    Here is a print screen..
    http://images.unbrokenphotography.co.uk/BridgeError.jpg

    Is there are answer to this problem?  This error message is appearing on an entire lab full of computers.  We are running Web Premium CS4
    I have tried to reset the Bridge Preferences:
    Hold down the Ctrl key and click on Bridge icon to start.
    Should get a reset window with 3 options.
    Choose the first option
    I still get "Runtime Error!   Program: C:\Prgram Files\Adobe\Adobe Bridge CS4\Bridge.exe  R6002 -floating point support not loaded"

  • Invalid Floating Point Error

    I have one Captivate 3 project published as a Stand Alone
    project with Flash 8 selected. There are 36 slides, no audio, no
    eLearning, SWF size and quality are high.
    One person who runs this gets an "Invalid Floating Point"
    error when he tries to run it the first time. He is running Windows
    XP SP2, Firefox 3.0.4. and Flash Player 10.0.12.36. Other Captivate
    projects I've created run fine for him. This one sometimes runs
    after the first Error message.
    Any thoughts on the cause and fix?
    Thanks,
    Janet

    iMediaTouch probably doesn't support Floating Point formats - it certainly doesn't mention them in the advertising. Try saving your files as 24-bit PCMs, and they should import fine.

Maybe you are looking for