Floating point operations is slower when small values are used?

I have the following simple program that multiplies two different floating point numbers many times. As you can see, one of the numbers is very small. When I calculate the time of executing both multiplications, I was surprised that the little number takes much longer than the other one. It seems that working with small doubles is slower... Does anyone know what is happening?
public static void main(String[] args) throws Exception
        long iterations = 10000000;
        double result;
        double number = 0.1D;
        double numberA = Double.MIN_VALUE;
        double numberB = 0.0008D;
        long startTime, endTime,elapsedTime;
        //Multiply numberA
        startTime = System.currentTimeMillis();
        for(int i=0; i < iterations; i++)
            result = number * numberA;
        endTime = System.currentTimeMillis();
        elapsedTime = endTime - startTime;
        System.out.println("
        System.out.println("Number A)
Time elapsed: " + elapsedTime + " ms");
        //Multiply numberB
        startTime = System.currentTimeMillis();
        for(int i=0; i < iterations; i++)
            result = number * numberB;
        endTime = System.currentTimeMillis();
        elapsedTime = endTime - startTime;
        System.out.println("
        System.out.println("Number B)
Time elapsed: " + elapsedTime + " ms");
    } Result:
Number A) Time elapsed: 3546 ms
Number B) Time elapsed: 110 ms
Thanks,
Diego

Verrry interrresting... After a few tweaks (sum & print multiplication result to prevent Hotspot from removing the entire loop, move stuff to one method to avoid code alignment effects or such, loop to get Hotspot compile everything; code below),
I find that "java -server" gives the same times for both the small and the big value, whereas "java -Xint" and "java -client" exhibit the unsymmetry. So should I conclude that my CPU floating point unit treats both values the same, but the client/server compilers do something ...what?
(You may need to add or remove a zero in "iterations" so that you get sane times with -client and -server.)
public class t
    public static void main(String[] args)
     for (int n = 0; n < 10; n++) {
         doit(Double.MIN_VALUE);
         doit(0.0008D);
    static void doit(double x)
        long iterations = 100000000;
        double result = 0;
        double number = 0.1D;
        long start = System.currentTimeMillis();
        for (int i=0; i < iterations; i++)
            result += number * x;
        long end = System.currentTimeMillis();
        System.out.println("time for " + x + ": " + (end - start) + " ms, result " + result);
}

Similar Messages

  • Qosmio F50 - Webcam error - Invalid floating point operation

    Hi
    I have Qosmio F50 (4 Weeks old) problem is after two weeks webcam has stopped working *Invalid floating point operation*
    I have to close program via task manager, *Camera assistant software not responding*.
    Have tried following.
    Update all drivers, system restore
    Toshiba help line after all efforts suggested complete reinstall this is to aggressive for me as it would loose certain software on laptop that I had to transfer from old PC and had to plead with certain software companies to transfer (only one license etc).
    Has anybody else had this problem and is there a simple solution
    Will

    Hi,
    I have the same problem, Laptop Qosmio F50 is 4 weeks old and now the webcam stopped working.... it's quite annoying, whenever I start the application it says ' Invalid floating point operation'. To me this sounds as some issues in the software and the compatibility on vista, I think it could happen after putting the laptop to hibernate or suspension state and then when it comes back, the webcam stops working. so let's see if toshiba realeases a fix or new version quickly, otherwise I would be quite disspointed with such a good laptop.

  • Error - "Invalid floating point operation"

    I keep getting a message that says "invalid floating point operation" and the files that I am trying to read are scrambled.  They used to be ok.  Please advise....

    Hi,
    I have the same problem, Laptop Qosmio F50 is 4 weeks old and now the webcam stopped working.... it's quite annoying, whenever I start the application it says ' Invalid floating point operation'. To me this sounds as some issues in the software and the compatibility on vista, I think it could happen after putting the laptop to hibernate or suspension state and then when it comes back, the webcam stops working. so let's see if toshiba realeases a fix or new version quickly, otherwise I would be quite disspointed with such a good laptop.

  • Question in floating point operation

    Hi,
    I have question in java floating point operation.
    public class test
         public static void main(String args[])
              double d1 = 243.35 ;
              double d2 = 2.3 ;
              System.out.println(d1 * d2) ;
              System.out.println((float)d1 * (float)d2) ;
    The result is,
    java version "1.4.1_02"
    Java(TM) 2 Runtime Environment, Standard Edition (build 1.4.1_02-b06)
    Java HotSpot(TM) Client VM (build 1.4.1_02-b06, mixed mode)
    5.597049999999999E8
    5.5970502E8
    Though the multiplication does not result irrational number like 1/3, the result of the first statement is not accurate enough. In our project, this multiplication involves with money and we cannot ignore this.
    Can anyone suggest why this is happening? Do I need to convert all the numbers to float to avoid this...Or Is it a bug?
    ~ Sathiya Dhanapal.

    The underlying problem is that not all numbers can be represented exactly in a floating point representation. But if you perform all calculations using doubles and then round to two fractional digits at the end you should get a "correct" result UNLESS you have used ill-conditioned formulas introducing other kinds of arithmetic errors.
    There's another way around this when it comes to counting money and that's to use integers (long or int). You convert every number to the lowest monetary unit (like a cent or whatever). Every money-amount can now be represented exactly but you still have to be careful because the rounding problem is still there (What do you do with the last cent when you split 100 cents in 3).
    In your example the "more correct" you've got from using floats instead of doubles is only an illusion. The result has been implictly rounded becasuse fewer bits have been used. If you round the double result to the same precision as the float result, they're the same.
    The important lesson in all this is TO KNOW WHEN TO ROUND.

  • Dynamic sql reurns no data when multiple values are passed.

    (Dynamic sql returns no data when multiple values are passed.)
    Hi,
    While executing the below dynamic sql in the procedure no data is returned when it has multiple input values.
    When the input is EMPID := '1'; the procedure works fine and returns data.Any suggestion why the procedure doen't works when input as EMPID := '1'',''2'; is passed as parameter?
    =======================================================
    create or replace PROCEDURE TEST(EMPID IN VARCHAR2, rc OUT sys_refcursor)
    IS
    stmt VARCHAR2(9272);
    V_EMPID VARCHAR2(100);
    BEGIN
    V_EMPID :=EMPID;
    stmt := 'select * from TEST123 where Empid is NOT NULL';
    IF V_EMPID <> '-1' THEN
    stmt := stmt || ' and Empid in (:1)';
    ELSE
    stmt := stmt || ' and -1 = :1';
    END IF;
    OPEN rc FOR stmt USING V_EMPID;
    END Z_TEST;
    ============================================================
    Script for create table
    ==================================================================
    CREATE TABLE TEST123 (
    EMPID VARCHAR2(10 BYTE),
    DEPT NUMBER(3,0)
    ===========================================
    Insert into PDEVUSER.TEST123 (EMPID,DEPT) values ('1',20);
    Insert into PDEVUSER.TEST123 (EMPID,DEPT) values ('2',10);
    Insert into PDEVUSER.TEST123 (EMPID,DEPT) values ('3',30);
    Insert into PDEVUSER.TEST123 (EMPID,DEPT) values ('3',30);
    Insert into PDEVUSER.TEST123 (EMPID,DEPT) values ('2',10);
    =============================================
    Select * from TEST123 where Empid in (1,2,3)
    EMPID DEPT
    1     20
    2     10
    3     30
    3     30
    2     10
    ===================================================================
    Any suggestion why the procedure doen't works when input EMPID := '1'',''2';?
    Thank you,

    The whole scenario is a little strange. When I tried to compile your procedure it couldn't compile, but I added the missing info and was able to get it compiled.
    create or replace PROCEDURE TEST (EMPID IN VARCHAR2, rc OUT sys_refcursor)
    IS
      stmt        VARCHAR2 (9272);
      V_EMPID     VARCHAR2 (100);
    BEGIN
      V_EMPID := EMPID;
      stmt := 'select * from TEST123 where Empid is NOT NULL';
      IF V_EMPID = '-1' THEN
        stmt := stmt || ' and Empid in (:1)';
      ELSE
        stmt := stmt || ' and -1 = :1';
      END IF;
      OPEN rc FOR stmt USING V_EMPID;
    END;If you pass in 1 as a parameter, it is going to execute because the statement that it is building is:
    select * from TEST123 where Empid is NOT NULL and -1 = 1Although the syntax is valid -1 will never equal 1 so you will never get any data.
    If you pass in 1,2 as a parameter then it is basically building the following:
    select * from TEST123 where Empid is NOT NULL and -1 = 1,2This will cause an invalid number because it is trying to check where -1 = 1,2
    You could always change your code to:
    PROCEDURE TEST (EMPID IN VARCHAR2, rc OUT sys_refcursor)
    IS
      stmt        VARCHAR2 (9272);
      V_EMPID     VARCHAR2 (100);
    BEGIN
      V_EMPID := EMPID;
      stmt := 'select * from TEST123 where Empid is NOT NULL';
      stmt := stmt || ' and Empid in (:1)';
      OPEN rc FOR stmt USING V_EMPID;
    END;and forget the if v_empid = '-1' check. If you pass in a 1 it will work, if you pass in 1,2 is will work, but don't pass them in with any tick marks.

  • ORA-12721: operation cannot execute when other sessions are active

    Hi,
    I started my DB like following :
    1) Change INIT.ORA file;  unset parallel_server parameter.
    2) Execute these commands:
    STARTUP MOUNT ;
    ALTER SYSTEM ENABLE RESTRICTED SESSION;
    ALTER SYSTEM SET JOB_QUEUE_PROCESSES=0;
    ALTER SYSTEM SET AQ_TM_PROCESSES=0;
    ALTER DATABASE OPEN;
    SHUTDOWN IMMEDIATE;
    SQL> STARTUP RESTRICT  pfile='C:\oracle\product\10.2.0\db_1\database\initORCL.ora';
    ORACLE instance started.
    SQL> alter database national character set INTERNAL_CONVERT UTF8;
    alter database national character set INTERNAL_CONVERT UTF8
    ERROR at line 1:
    ORA-12721: operation cannot execute when other sessions are activeWhy this error when DB is opened in strict and I'm the only user ?
    SQL> select count (*) from v$session;
      COUNT(*)
            20Any solution ?
    Thank you.

    Hi
    This operation is dangerous, please ensure that you have a full backup before doing that operation.
    Please use that order :
    SHUTDOWN IMMEDIATE;
    -- make sure there is a database backup you can rely on, or create one
    STARTUP MOUNT;
    ALTER SYSTEM ENABLE RESTRICTED SESSION;
    ALTER SYSTEM SET JOB_QUEUE_PROCESSES=0;
    ALTER SYSTEM SET AQ_TM_PROCESSES=0;
    ALTER DATABASE OPEN;
    ALTER DATABASE CHARACTER SET <new_character_set>;
    -- a alter database takes typically only a few minutes or less,
    -- it depends on the number of columns in the database, not the
    -- amount of data.
    SHUTDOWN;
    Please note that :
    The command requires the database to be
    open but only one session, the one executing the command, is allowed.
    For the above error conditions Oracle9i will report one of the errors:
    ORA-12719: operation requires database is in RESTRICTED mode
    ORA-12720: operation requires database is in EXCLUSIVE mode
    ORA-12721: operation cannot execute when other sessions are active
    Oracle9i can also report:
    ORA-12718: operation requires connection as SYS
    if you are not connect as SYS (INTERNAL, "/ AS SYSDBA").
    Let us know if this helps.
    regards,
    Hub
    Edited by: Hub on Dec 10, 2008 1:22 PM

  • In column Chart when Y values are grater than y linear axis maximum it doesnt show the Bar

    Hi Guys,
    In column Chart when Y values are grater than y linear axis maximum it doesnt show the Bar.But i want show the bar upto the max limit of y linear axis without changing the max limit.
    Consider following example:
    Y values are 80 90 200 300
    and following are the output :
    Left:When i am not setting maximum property of linear axis.
    Right :When i am setting maximum property of linear axis to 200.
    In right 4th bar is not visible bcoz value for that bar is 300 which is excedding  maxium.But i want the 4th bar to appear same as 3rd bar.
    How i can do this?
    Thanks in advance.

    Are you going to show the bar going past the maximum value?
    If not, then you should change the Y value when entered into the array to the maximum value allowed. i.e.
    if(itemYValue > maxAllowedValue) {
         itemYValue = maxAllowedValue;
    Where maxAllowedValue is a variable you set on the application to control the maximum value for the chart.
    This is assuming that you are loading the values into an Array before updating the chart dataprovider with that array.

  • Performance when OUTER JOINS are used

    Hello Everyone,
    I have read in asktom.com about the performance of an SQL query when OUTER JOINS are used. I am not able to find the same artical and would like any of you guys to clarify if the sql that I have written would be better or not.
    1. I haven't used OUTER JOINS in an SQL query. The query used 3-4 tables.
    In those 3-4 tables one table is transaction table (big one) and the other are tables like transaction_type.
    2. The transactions tables thas the typ_code and the typ_desc is present in transaction_type. It is one(transaction_type) to many(transactions) relationship
    3. And also as all the typ_code of transactions tables has definte value in transaction_types table, I thought of not usng OUTER JOINS.
    Would you guys agree with me?

    I have read in asktom.com about the performance of an
    SQL query when OUTER JOINS are used. I am not able to
    find the same artical and would like any of you guys
    to clarify if the sql that I have written would be
    better or not.The first thing to consider using outer joins or not - is whether the required business functionality needs them or not? Performance should be only the second thing because getting invalid results VERY FAST doesn't make any sense :)
    Gints Plivna
    http://www.gplivna.eu

  • TS4002 when to persons are using one apple ID and they sync their contacts to gather then first sync contacts are deleted. how we get it back?

    when to persons are using one apple ID and they sync their contacts to gather then first sync contacts are deleted. how we get it back?

    You can share the same Apple ID for purchasng form the iTunes and app stores without any problems, but you should all used separate iCloud accounts with separate Apple IDs.  (You are not required to use the same ID for iCloud and other services as you do for the iTunes store.)  This will prevent you from ending up with merged data.  You should also use separate Apple IDs for iMessage and FaceTime or you will end up getting each other's text messages and FaceTime calls.
    This article may be of interest: http://www.macstories.net/stories/ios-5-icloud-tips-sharing-an-apple-id-with-you r-family/, as well as this video: http://macmost.com/setting-up-multiple-ios-devices-for-messages-and-facetime.htm l.

  • Niagara II Floating Point Operations

    Niagara II has much improved floating point performance over Niagara I, however I'm wondering if performance of floating point intensive threads could be improved, by amalgamating the floating point processing from each core to a dedicated unit that can execute in parallel, the instructions from all threads, such that if a single core, experiences a floating point intensive load, the floating point load aggregate over the entire processor is better optimized?

    pfirmst wrote:
    Niagara II has much improved floating point performance over Niagara I, however I'm wondering if performance of floating point intensive threads could be improved, by amalgamating the floating point processing from each core to a dedicated unit that can execute in parallel, the instructions from all threads, such that if a single core, experiences a floating point intensive load, the floating point load aggregate over the entire processor is better optimized?I'm not a hardware designer, but I think there are two problems with this approach.
    a. There would probably need to be extra interconnect and arbitration to get from the issue pipeline to the shared floating-point units and back again with the result. This would tend to add latency to the floating-point instruction execution and would probably be bad for performance. For example, the floating-point latency on T1 is about 26 cycles and on T2 it's about 6 cycles.
    b. In order to get more floating-point performance from a single thread, the issue logic would also need to be changed to be able to issue more floating-point instructions in a single cycle (i.e. superscalar issue). This would be good for single thread performance, but would require more complexity and space, and may impact the number of cores/threads that can fit on a single chip. The correlary is that since each T2 core can only issue two floating-point instructions per cycle (one from each of two threads), each core could make use of at most two floating-point units.
    On CMT chips, sharing is good, because it leads to higher efficiency and utilization,
    but too much sharing can also hurt performance. There needs to be balance in the design.
    Peter.

  • Error in when null values are passed to datefield

    Hi all,
    We are facing some issue with null values in date fields while calling a stored procedure using JDBC Adapter in one of the interfaces.
    When the value is null, XI gives errors in the communication channel.
    Case 1 , When the value is mapped to blank. : The adapter gives an error related to date format. Unsparseable date “”.
    Case 2 , When the value is not mapped at all : The adapter gives an error related to wrong number of arguments for the stored procedure.
    One option for fixing this issue is to hardcode the value to all zeros in a appropriate date format. However this is not acceptable in our case.
    Did anybody face this issue before. If yes what was the approach taken. Can you please let me know if anybody has any inputs on this.
    Thanks in advance,
    Younus

    you can clear the field key tags mandatory in the XML Schema interpreter parameter and make the Empty string value to Empty string from null value.
    For mapping : you can pass a value that is of the same format of date; but you can take your own value in the database since you are parsing the date format from one to other
    thanks
    nikhil

  • Cisco IronPort Plug-In 7.3 breaks when multiple profiles are used?

    In our testing of the Cisco IronPort Plug-In 7.3 we found that if seperate Outlook profiles are used that are configured to different e-mail accounts the plug-in gives an error.
    Here's the scenario.
    Profile A configured with [email protected] up and running receives the BCS Configuratoin File and the plug-in recognizes it and enables the ENCRYPT button.   User1 can use Outlook along with ENCRYPT and all works well.
    But, if that same workstation users opens a different Outlook mail profile is opened that is configured to a different e-mail account.  Profile B configured with [email protected] the following error is generated:  "An error occurred during C:\ProgramData\Cisco\Cisco IronPort Email Security Plug-in\user1\config_2.xml configuartion file initialization.  Some settings have been set to the default values."   Outlook works fine, the decrypt button is greyed out, which is expected, [email protected] is not ENCRYPT enabled.
    The problem is when the user opens up Profile A again, a different error occurs "
    "An error occurred during C:\ProgramData\Cisco\Cisco IronPort Email Security Plug-in\user1\config_1.xml configuartion file initialization.  Some settings have been set to the default values." and the ENCRYPT button is still disabled, even though this user is authorized for ENCRYPTION.   At this point the user has to open the BCS Configuration File again, which does give the message 'This message contains a secure attachment with settings for [email protected]  Do you want to apply these settings?".   If they answer YES, the ENCRYPT button is re-enabled.
    Is Cisco aware of this?   What is the resolution?
    Thanks.

    Same workstation AD login that has full access to both e-mail accounts. 
    Email account A profile A is the same as the workstation login used.   Email account B profile B is a different e-mail address / AD object but user A has full access to the mailbox.
    I would expect Encryption to work for Profile A and not for Profile B, e-mail address B was never sent the configuration file.  But when I go back to use Profile A, encryption is no longer enabled, requireing me to run the configuration again.

  • Why we are using SID in DSO when there we are using star schema in BI

    can anyone answer me why we are using SID in DSO also, i mean what is the need of SID in DSO?

    The reason basically is that the entire query api in BW is based on SIDs
    If you look at a sql of a query that is generated when you run a report you can see this
    Example..
    If you put a selection of period = 02.2009
    In the SQL you will not see "where period = 02.2009" you will see "where sid.period = '000100001010" or something like that
    The whole query  is like this for Infoproviders of DSOs and Infocubes
    Yes it is annoying - but that't  the way it is..
    So if you have a DSO you wish to report on you need the SID for the SQL to fire..!
    On an operational daya to day side - if my cubes are 1:1 granularity with my DSOs then I prefer to put SID activation on the DSOs - two reasons
    1. so the cube load is quicker because the SID generation has already taken place (is this important? never sure but I always do it)
    2. future use of the DSO as a reporting object (this was before the days of the operational store as part of a LSA structure)

  • Floating point operations....

    We ran into a serious calculation problem, to give you a few
    examples:
    trace(1.3456-1.3454) // gives 0.00019999999999997797 but
    should be 0.0002 clearly
    trace(1.3456*1.3456) // gives 1.8106393599999997 but should
    be 1.81063936
    Any idea on how to resolve the problem?
    Thanks,
    Dan

    This is just a result of the limitations of accuracy in the
    binary representation of decimal numbers.
    http://kb.adobe.com/selfservice/viewContent.do?externalId=tn_13989&sliceId=1
    There's some discussion about as3 in the link below. But the
    general principles are the same for as2 even though the same code
    (apparently) might give different results in as2.
    http://www.kirupa.com/forum/archive/index.php/t-247416.html

  • How should I set up my VI so that I can use the linear fit coefficient data analysis program, when my values are coming from while loops within a sequence structure?

    I'm attempting to create a calibration program, using the printer port, and a Vernier Serial Box by modifying a calibration program designed for the serial box.
    There are six calibration points, and to collect them, I have it controlled by while loops so that the numbers are taken when a button is pushed, and this is inside a sequence structure so that I can get the six different points. I feed these numbers into two different arrays (for x and y values) and then try to use the linear coefficient analysis on these points, but the values for the slope and intercepts it returns are not correc
    t.
    If I cut out the array and coefficient analysis, and feed the same numbers in directly without the while loop and sequence structures, it produces the proper values... I don't know why the numbers it is producing are different, and I'd really like to know.
    Thanks,
    Karinne.

    I would use a data manager sub-vi that would be called by each from of the sequence structure that produced a data point. The data manager sub-vi could auto append new items or could place items in a specific entry of an array. Later on when you want to calculate the linear fit, call the sub-vi to return the array of values.
    Stu

Maybe you are looking for

  • SharePoint Navigation Error:The context has expired and can no longer be used. (Exception from HRESULT: 0x80090317)

    Hi, I take a exeption  on the  SharePoint 2013 left navigation.  Exeption:  "The context has expired and can no longer be used. (Exception from HRESULT: 0x80090317)" I searched  this exeption keyword on the internet and  I find usualy 3 results 1)che

  • Cant uninstall Itunes 7.7.1.11

    So I turn Itunes on and it asks if I want to upgrade to 8.0 and I click yes so i downloads everything and installs everything nothing looks like it went wrong but then when I turn it on i get an error box that says Warning! The registry settings used

  • Downloaded update and now it won't open

    Yesterday I downlaoded the new iTunes update and now it will not open. I am running Norton and Microsoft Anti-spyware and took some hints from other messages and non of those have worked. Anyone with ideas to fix this please send them to me and thank

  • Not getting Response from RFC

    Hi,     I am doing RFC to File. I could generate the FILE successfully. But I am not getting Response from RFC. I am getting empty payload. I am doing with out BPM. I did succesfully File-RFC-File. but here RFC is the sender. I have some doubts  in d

  • How to know the service name of oracle server

    write a query to get the servcie name of oracle from oracle tables