[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

Similar Messages

  • 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;

  • Port of Giac [Longfloat] Library to HP Prime allowing [Variable Precision] Floating Point Arithmetic

    HP Prime CAS is based on Giac, but [ misses ] some of its Special Purpose Libraries like the Giac [ Longfloat ] Library, which if [ Ported ] would allow HP Prime to be the First ( handheld ) Calculator to provide [ Variable Precision ] Floating Point Arithmetic routines ( fully integrated at its CAS Kernel level ). HP Prime already have internal calls to [ Longfloat ] library, but resulting in [ Error Messages ], like when selecting more than 14 Digits in [ evalf ] Numerical evaluation, as for example: evalf( 1/7, 14 ) producing 0.142857142857 and evalf( 1/7, 15 ) resulting in "Longfloat library not available Error: Bad Argument Value" The same happens when one tries to Extend the [ Digits ] variable to a value greater than 13, like Digits := 50 which returns Digits := 13 as output ( from any specified value higher than 13 ).  The porting of [ Longfloat ] library to HP Prime, would open many New opportunities in [ handheld ] Numerical Computation, usually available only on Top Level Computer Algebra Systems, like Maple, Mathematica or Maxima, and also on Giac/XCas. Its worth mentioning that Any [ Smartphone ] with Xcas/Giac App installed, can fully explore [ Variable Precision ] Floating Point Arithmetic, on current ARM based architectures, which means that a Port of [ Longfloat ] Library from Giac to HP Prime, although requiring some considerable amount of labor, is Not an impossible task. The Benefits of such Longfloat [ Porting ] to a handheld Calculator like HP Prime, would put it several levels Up on the list of Top current Calculator Features, miles and miles away from competitors like TI Nspire CX CAS and Casio ClassPad II fx-CP 400 ... Even HP 49/50g have third party developed routines with limited Variable Precision floating point support, while such feature is Not fully integrated to their native CAS Kernel. For those who do not see "plenty" reason for a [ Longfloat ] Porting to HP Prime its needless to say that the PRIMARY reason for ANY [ CALCULATOR ] is to CALCULATE ! and besides Symbolic Computation ( already implemented on all contemporaries top calculator models ), Arbitrary / [ Variable Precision ] Floating Point Arithmetic is simply The TOP of the TOP ( of the IceCream ) in [ Numerical ] Computation ! ( and beside Computer Algebra Manipulation routines, one of the Main reasons for the initial development of the major packages like Maple, Mathematica or Maxima ).

    Thanks for the Link to [ HPMuseum.org ] Page with Valuable Details about the Internal Floating Point implementations both on Home and CAS environments of HP Prime. Its interesting to point to the fact that HP 49/50g has a [ Longfloat ] Version 3.93 package implementation ( with the Same Name but Distinct Code from the Giac Library ) available at [ http://www.hpcalc.org/details.php?id=5363 ] Also its worth mentioning [ Wikipedia ] pages on Arbitrary Precision Arithmetic like [ https://en.wikipedia.org/wiki/Arbitrary-precision_arithmetic ], [ https://en.wikipedia.org/wiki/List_of_arbitrary-precision_arithmetic_software ] and [ https://en.wikipedia.org/wiki/List_of_computer_algebra_systems ] and the Xcas/Giac project at [ https://en.wikipedia.org/wiki/Xcas#Giac ] and Official Site at [ http://www-fourier.ujf-grenoble.fr/~parisse/giac.html ] It would be a Dream come True when a Fully Integrated Variable Precision Floting Point Arithmetic package where definetively incorporated to HP Prime CAS Kernel, like the Giac [ Longfloat ] Library, allowing the Prime to be the First calculator with such Resource trully incorporated at its [ Kernel ] level ( and not like an optional third party module as the HP 49/50g one, which lacks complete integration with their respective Kernel, since HP 49/50g does not have native support for Longfloats ).

  • 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);

  • Floating Point arithmetic conversion

    Hi Everyone,
    Can you tell me how to convert a floating point arithmetic field value to a currency field value.
    thanks,
    chan

    Hi,
    I hope simple move statement should work.
    MOVE l_float TO l_curr.
    Make sure that curr field has enough length.
    Thanks,
    Vinod.

  • 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

  • Floating point arithmetic

    Hi everybody,
    This line:
    System.out.println((0.1+0.7)*10);outputs 7.999999999999999
    This is due to how floating point numbers are stored. When writing
    a code, sometimes it behaves in an intended way, sometimes it doesn't
    (like the one above). Is there a way to "predict" when the code is ok and
    when isn't ? Are there any tips to be aware of to get around that kind
    of problems ?
    Cheers,
    Adrian

    No. Using BigDecimal just because you don't understand how floating-point numbers work would be... um... short-sighted. And it wouldn't help, either. As soon as you divide 1 by 3 then you have to know how decimal numbers work, which is essentially the same problem.
    Edit: I forgot the forum hasn't been automated to provide the mandatory link for people who ask this question. We still have to do it by hand.
    http://docs.sun.com/source/806-3568/ncg_goldberg.html
    Edited by: DrClap on Oct 11, 2007 3:02 PM

  • 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

  • [SOLVED] bash and xterm - which files get read and referenced?

    I currently have my user shell set as /bin/sh (which, as I'm sure you are aware, is a symlink to bash). When I launch xterm, none of my config files seem to be read or sourced. If I login from the console, all is correct.
    According to the documentation I've read, when bash is invoked as sh, it should read /etc/profile, and then .profile, and finally .shrc (which is recommended to be explicitly sourced from .profile). I can see that /etc/profile is being read, as the PATH is being updated from items in /etc/profile.d, but none of my config files in ~ are being read.
    I put in a unique alias in each of .bash_profile, .bashrc, .profile, and .shrc to try to trace the files being read. In console, this reveals that .profile and .shrc are being read (as I would expect). But, in xterm, no aliases are being read.
    Also, PS1 is set to sh-4.2$ (literally set as '\s-\v\$ '). I have tried to grep that sequence in /etc, but that failed to hit on anything.
    I don't have my own .Xresources and nothing in .xinitrc redefines xterm behavior. The only switches I am explicitly sending to xterm redefine appearance (background/foreground color and font).
    The only other relevant piece of information I can think of is that I am using the slim login manager and in slim.conf it defines: login_cmd exec /bin/bash -login ~/.xinitrc %session. I changed that to /bin/sh, but it had no effect.
    Any ideas?
    Solution
    Adding
    XTerm*.LoginShell: True
    to ~/.Xdefaults will cause xterm to behave as expected.
    Last edited by archnet (2011-05-11 00:40:49)

    dmz wrote:
    To answer your actual question:
    strace -eopen xterm
    strace -eopen sh
    Here is the output:
    sh-4.2$ strace -eopen xterm
    open("/etc/ld.so.cache", O_RDONLY) = 3
    open("/usr/lib/libXft.so.2", O_RDONLY) = 3
    open("/usr/lib/libXaw.so.7", O_RDONLY) = 3
    open("/lib/libncursesw.so.5", O_RDONLY) = 3
    open("/lib/libc.so.6", O_RDONLY) = 3
    open("/usr/lib/libfontconfig.so.1", O_RDONLY) = 3
    open("/usr/lib/libX11.so.6", O_RDONLY) = 3
    open("/usr/lib/libXmu.so.6", O_RDONLY) = 3
    open("/usr/lib/libXt.so.6", O_RDONLY) = 3
    open("/usr/lib/libICE.so.6", O_RDONLY) = 3
    open("/usr/lib/libfreetype.so.6", O_RDONLY) = 3
    open("/usr/lib/libXrender.so.1", O_RDONLY) = 3
    open("/usr/lib/libXext.so.6", O_RDONLY) = 3
    open("/usr/lib/libXpm.so.4", O_RDONLY) = 3
    open("/usr/lib/libz.so.1", O_RDONLY) = 3
    open("/usr/lib/libexpat.so.1", O_RDONLY) = 3
    open("/usr/lib/libxcb.so.1", O_RDONLY) = 3
    open("/lib/libdl.so.2", O_RDONLY) = 3
    open("/usr/lib/libSM.so.6", O_RDONLY) = 3
    open("/usr/lib/libXau.so.6", O_RDONLY) = 3
    open("/usr/lib/libXdmcp.so.6", O_RDONLY) = 3
    open("/lib/libuuid.so.1", O_RDONLY) = 3
    open("/proc/meminfo", O_RDONLY) = 3
    open("/home/archnet/.Xauthority", O_RDONLY) = 4
    open("/home/archnet/.Xdefaults", O_RDONLY) = -1 ENOENT (No such file or directory)
    open("/usr/lib/locale/locale-archive", O_RDONLY) = 4
    open("/usr/share/X11/locale/locale.alias", O_RDONLY) = 4
    open("/usr/share/X11/locale/locale.alias", O_RDONLY) = 4
    open("/usr/share/X11/locale/locale.dir", O_RDONLY) = 4
    open("/usr/share/X11/locale/en_US.UTF-8/XLC_LOCALE", O_RDONLY) = 4
    open("/home/archnet/.Xdefaults-natoufa", O_RDONLY) = -1 ENOENT (No such file or directory)
    open("/home/archnet/.Xdefaults", O_RDONLY) = -1 ENOENT (No such file or directory)
    open("/usr/share/X11/app-defaults/XTerm", O_RDONLY) = 4
    open("/etc/ld.so.cache", O_RDONLY) = 4
    open("/usr/lib/libXcursor.so.1", O_RDONLY) = 4
    open("/usr/lib/libXfixes.so.3", O_RDONLY) = 4
    open("/home/archnet/.icons/default/cursors/xterm", O_RDONLY) = -1 ENOENT (No such file or directory)
    open("/home/archnet/.icons/default/index.theme", O_RDONLY) = -1 ENOENT (No such file or directory)
    open("/usr/share/icons/default/cursors/xterm", O_RDONLY) = -1 ENOENT (No such file or directory)
    open("/usr/share/icons/default/index.theme", O_RDONLY) = -1 ENOENT (No such file or directory)
    open("/usr/share/pixmaps/default/cursors/xterm", O_RDONLY) = -1 ENOENT (No such file or directory)
    open("/usr/share/pixmaps/default/index.theme", O_RDONLY) = -1 ENOENT (No such file or directory)
    open("/home/archnet/.icons/default/cursors/sb_v_double_arrow", O_RDONLY) = -1 ENOENT (No such file or directory)
    open("/home/archnet/.icons/default/index.theme", O_RDONLY) = -1 ENOENT (No such file or directory)
    open("/usr/share/icons/default/cursors/sb_v_double_arrow", O_RDONLY) = -1 ENOENT (No such file or directory)
    open("/usr/share/icons/default/index.theme", O_RDONLY) = -1 ENOENT (No such file or directory)
    open("/usr/share/pixmaps/default/cursors/sb_v_double_arrow", O_RDONLY) = -1 ENOENT (No such file or directory)
    open("/usr/share/pixmaps/default/index.theme", O_RDONLY) = -1 ENOENT (No such file or directory)
    open("/home/archnet/.icons/default/cursors/sb_h_double_arrow", O_RDONLY) = -1 ENOENT (No such file or directory)
    open("/home/archnet/.icons/default/index.theme", O_RDONLY) = -1 ENOENT (No such file or directory)
    open("/usr/share/icons/default/cursors/sb_h_double_arrow", O_RDONLY) = -1 ENOENT (No such file or directory)
    open("/usr/share/icons/default/index.theme", O_RDONLY) = -1 ENOENT (No such file or directory)
    open("/usr/share/pixmaps/default/cursors/sb_h_double_arrow", O_RDONLY) = -1 ENOENT (No such file or directory)
    open("/usr/share/pixmaps/default/index.theme", O_RDONLY) = -1 ENOENT (No such file or directory)
    open("/home/archnet/.icons/default/cursors/sb_up_arrow", O_RDONLY) = -1 ENOENT (No such file or directory)
    open("/home/archnet/.icons/default/index.theme", O_RDONLY) = -1 ENOENT (No such file or directory)
    open("/usr/share/icons/default/cursors/sb_up_arrow", O_RDONLY) = -1 ENOENT (No such file or directory)
    open("/usr/share/icons/default/index.theme", O_RDONLY) = -1 ENOENT (No such file or directory)
    open("/usr/share/pixmaps/default/cursors/sb_up_arrow", O_RDONLY) = -1 ENOENT (No such file or directory)
    open("/usr/share/pixmaps/default/index.theme", O_RDONLY) = -1 ENOENT (No such file or directory)
    open("/home/archnet/.icons/default/cursors/sb_down_arrow", O_RDONLY) = -1 ENOENT (No such file or directory)
    open("/home/archnet/.icons/default/index.theme", O_RDONLY) = -1 ENOENT (No such file or directory)
    open("/usr/share/icons/default/cursors/sb_down_arrow", O_RDONLY) = -1 ENOENT (No such file or directory)
    open("/usr/share/icons/default/index.theme", O_RDONLY) = -1 ENOENT (No such file or directory)
    open("/usr/share/pixmaps/default/cursors/sb_down_arrow", O_RDONLY) = -1 ENOENT (No such file or directory)
    open("/usr/share/pixmaps/default/index.theme", O_RDONLY) = -1 ENOENT (No such file or directory)
    open("/home/archnet/.icons/default/cursors/sb_left_arrow", O_RDONLY) = -1 ENOENT (No such file or directory)
    open("/home/archnet/.icons/default/index.theme", O_RDONLY) = -1 ENOENT (No such file or directory)
    open("/usr/share/icons/default/cursors/sb_left_arrow", O_RDONLY) = -1 ENOENT (No such file or directory)
    open("/usr/share/icons/default/index.theme", O_RDONLY) = -1 ENOENT (No such file or directory)
    open("/usr/share/pixmaps/default/cursors/sb_left_arrow", O_RDONLY) = -1 ENOENT (No such file or directory)
    open("/usr/share/pixmaps/default/index.theme", O_RDONLY) = -1 ENOENT (No such file or directory)
    open("/home/archnet/.icons/default/cursors/sb_right_arrow", O_RDONLY) = -1 ENOENT (No such file or directory)
    open("/home/archnet/.icons/default/index.theme", O_RDONLY) = -1 ENOENT (No such file or directory)
    open("/usr/share/icons/default/cursors/sb_right_arrow", O_RDONLY) = -1 ENOENT (No such file or directory)
    open("/usr/share/icons/default/index.theme", O_RDONLY) = -1 ENOENT (No such file or directory)
    open("/usr/share/pixmaps/default/cursors/sb_right_arrow", O_RDONLY) = -1 ENOENT (No such file or directory)
    open("/usr/share/pixmaps/default/index.theme", O_RDONLY) = -1 ENOENT (No such file or directory)
    open("/dev/tty", O_RDWR) = 4
    open("/dev/ptmx", O_RDWR) = 4
    open("/home/archnet/.XCompose", O_RDONLY) = -1 ENOENT (No such file or directory)
    open("/usr/share/X11/locale/compose.dir", O_RDONLY) = 5
    open("/usr/share/X11/locale/en_US.UTF-8/Compose", O_RDONLY) = 5
    open("/usr/share/X11/XKeysymDB", O_RDONLY) = -1 ENOENT (No such file or directory)
    open("/usr/lib/gconv/gconv-modules.cache", O_RDONLY) = -1 ENOENT (No such file or directory)
    open("/usr/lib/gconv/gconv-modules", O_RDONLY) = 5
    open("/usr/share/terminfo/x/xterm", O_RDONLY) = 5
    sh-4.2$ strace -eopen sh
    open("/etc/ld.so.cache", O_RDONLY) = 3
    open("/lib/libreadline.so.6", O_RDONLY) = 3
    open("/lib/libncursesw.so.5", O_RDONLY) = 3
    open("/lib/libdl.so.2", O_RDONLY) = 3
    open("/lib/libc.so.6", O_RDONLY) = 3
    open("/dev/tty", O_RDWR|O_NONBLOCK) = 3
    open("/usr/lib/locale/locale-archive", O_RDONLY) = 3
    open("/proc/meminfo", O_RDONLY) = 3
    open("/etc/nsswitch.conf", O_RDONLY) = 3
    open("/etc/ld.so.cache", O_RDONLY) = 3
    open("/lib/libnss_files.so.2", O_RDONLY) = 3
    open("/etc/passwd", O_RDONLY|O_CLOEXEC) = 3
    open("/usr/lib/gconv/gconv-modules.cache", O_RDONLY) = -1 ENOENT (No such file or directory)
    open("/usr/lib/gconv/gconv-modules", O_RDONLY) = 3
    open("/home/archnet/.bash_history", O_RDONLY) = 3
    open("/home/archnet/.bash_history", O_RDONLY) = 3
    open("/usr/share/terminfo/x/xterm", O_RDONLY) = 3
    open("/etc/inputrc", O_RDONLY) = 3
    I don't see it attempting to read any sort of profile for shrc file.

  • 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

  • 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.

  • Error on floating point?

    One can expect that 1.2 * 3.0 equals 3.60
    But the following statement has the result: 3.5999999999999996
    - System.out.println(1.2 * 3.0);
    Why?
    How can I control or estimate the floating point error?
    Thanks in advance!

    It is not a Java problem or a Java error. It is inherent to floating-point arithmetic.
    1.2 can not be exactly represented in binary floating-point arithmetic. But 1.25 (that is 5 * (2 ^ -2)) can be.
    If your problem requires exact decimal arithmetic, use BigDecimal instead. (It is very slow compared to the conventional floating-point arithmetic).
    Please consult a textbook on numerical calculus for the techniques of dealing with floating-point error - it depends on the algorithm that you use for solving your problem.

  • Dtrace Floating Point gives error on x86

    When I try to create a floating point constant in dtrace x86:
    BEGIN
    printf ("%f", 1.0);
    exit (1);
    I get the error:
    dtrace: failed to compile script special.d: line 3: floating-point constants are not permitted
    Am I using the floating point constant incorrectly, or are floating point constants not permitted in the x86 platform.
    Thanks,
    Chip

    Then what is meant at the bottom of page 48 of the
    Solaris Dynamic Tracing Guide where it talks about
    floating-point constants?
    ChipSorry for not making that sufficiently clear. We are reserving that syntax for possible future use, but you cannot specify floating-point constants at present, and you cannot perform floating-point arithmetic in D. The only legal use of floating-point is that you can trace one or more data objects or structures that contain floating-point values and format the results using printf() and the various %f, %g formats.
    -Mike

Maybe you are looking for

  • Timeout Session - Expiration time of Webdynpro application

    Hello, I set the sap.expirationTime property of my application to 1 hour,  know the expiration time of my application is one hour. After time out (one hour) I am getting default 500 internal server error page. But as per the requirement we need to di

  • Maintaining External Alias for BSP Pages in EBP lauchpad

    Hello, Below is the problem mentioned : Our SRM production system is installed on a AIX server that has svuni299.its.it as fully qualified domain name. When we connect to the system using the url http://svuni299.its.it:8052/sap/bc/gui/sap/its/bbpstar

  • Chinese Character Search

    Hi All, I am working on an application which supports Chinese character search. I am having a column in one table which stores the chinese names. Now when this column contain only the chinese character the search query : select * from table where chi

  • Bad VGA Board

    I had been having problems with severe texture thrashing in games and have tried several things to fix it.   Finally, I installed a new board and it fixed the problem.  The first board stopped working in 3d games. What can I do about my MSI board?  I

  • Authentication proxy with Apps !!!!

    How can the iPhone doesn't support authentication proxy access for 3rd party apps ??? does anyone know how to get over that ?