Subtracting very small double value

i'm having trouble figuring this out..i'm sure it's a simple solution..anyhoo..i'm trying to run the following line of code
value=1-((1-b1[8+(i%classes)])*(1-b2[4+(i%classes)]));
let me point out that value is a double value, and b1 and b2 are double arrays...
the values of b1 and b2 are very small(around E-60)
the PROBLEM is that value returns 0.0 when i run my code instead of the small value. I'm sure it's something I'm doing/not doing, but I'd appreciate some help on what is going on. Also as a note, I'm running J2SE 1.3.1. I saw on the API that the min double value is supposed to be around E-324 but any suggestions people? Thanks!!

1-b1[8+(i%classes)]This is 1 - (10^-60), right? A double value only has about 16 significant digits, not 60, so the nearest possible double number to that is 1. Hence you get 1 - 1*1. There's a whole school of mathematics called "numerical analysis" that deals with questions like this. In this particular case, if b1[x] and b2[x] are always extremely small, you should evaluate the expression in advance so that it looks like b1 + b2 - b1*b2, which in turn will round to b1 + b2.
PC²

Similar Messages

  • Underflow Exception when trying to bind small double to BINARY_DOUBLE

    I get exception when trying to insert small double value (1.0E-131) into BINARY_DOUBLE column via jdbc.
    The exception I get:
    Exception in thread "main" java.sql.SQLException: Underflow Exception trying to bind 1.0000000000000001E-131
    at oracle.jdbc.driver.DoubleBinder.bind(OraclePreparedStatement.java:13856)
    at oracle.jdbc.driver.OraclePreparedStatement.setupBindBuffers(OraclePreparedStatement.java:2866)
    at oracle.jdbc.driver.OraclePreparedStatement.processCompletedBindRow(OraclePreparedStatement.java:2151)
    at oracle.jdbc.driver.OraclePreparedStatement.executeInternal(OraclePreparedStatement.java:3280)
    at oracle.jdbc.driver.OraclePreparedStatement.execute(OraclePreparedStatement.java:3390)
    at dbAccess.main(dbAccess.java:18)
    According to oracle documentation the smallest positive number the BINARY_DOUBLE column can store is 2.22507485850720E-308.
    I'm using oracle 10g r2 and thin jdbc driver.
    Any ideas?

    That is expected since a double is converted to a Oracle NUMBER before passing it to the database and Oracle NUMBER does not support 1.0e-131, the range is 1E-130 .. 10E125.
    Look at the SQL output below,
    SQL> select to_char(to_number(1.0e-131)) from dual;
    T
    0
    SQL> select to_char(to_number(1.0e-130)) from dual;
    TO_CHAR(TO_NUMBER(1.0E-130))
    1.000000000000000000000000000000000E-130
    ==
    Use oracle.sql.BINARY_DOUBLE for numbers like this.
    eg:
    preparedStatement.setBINARY_DOUBLE(1, new oracle.sql.BINARY_DOUBLE(1.0e-131));
    ==
    hope this helps.
    Ashok

  • Fast scaling of double values?

    So far, I use my own method to scale double values:
         * Scale decimal number via the rounding mode BigDecimal.ROUND_HALF_UP.
         * @param value Decimal value.
         * @param scale New scale.
         * @param roundingMode Optional rounding mode from BigDecimal.ROUND_... constants. (Default: BigDecimal.ROUND_HALF_UP)
         * @return Scaled number.
         * @since 1.8.3
        static public double getScaled(double value, final int scale, final int... roundingMode) {
            double result = value; //default: unscaled
            value = (Double.isNaN(value) || Double.isInfinite(value)) ? 0.0 : value; //reser NaN
            //use BigDecimal String constructor as this is the only exact way for double values
            int rm = BigDecimal.ROUND_HALF_UP;
            if (roundingMode != null && roundingMode.length > 0) {
                rm = roundingMode[0];
            result = new BigDecimal(""+value).setScale(scale, rm).doubleValue();
            return result;
        }//getScaled()BigDecimal offers scale methods, so I use them. The String constructor is also the only way to convert a double into a BigDecimal.
    This works fine but is quite slow on heavy number crunching with lots of scales. Is there a faster way?

    After heavy profiling of our number crunching apps, I replaced my former scaling method (with BigDecimal) with a costum version:
         * Get scaled decimal value with a fixed rounding method 'ROUND_HALF_UP'.
         * <p>
         * Note: there's also a getScaled() version that supports more rounding modes but is slower.
         * @param value Value to scale.
         * @param scale New scale.
         * @return Scaled values.
         * @since 2.14.0
         * @see #getScaled(double, int, int) Scaling with custom rounding mode.
        static public double getScaled(double value, final int scale) {
            double result = 0.0; //default: unscaled
            if (value != 0.0 && !Double.isNaN(value) && !Double.isInfinite(value)) {
                final BigDecimal bd = new BigDecimal(""+value);
                final int signum = bd.signum();
                final long l = bd.unscaledValue().abs().longValue();
                final int s = scale - bd.scale();
                if (s < 0) { //new scale is smaller than old scale
                    long l2 = l / (long) Math.pow(10.0, -s); //cut old unrequired scale
                    final long roundDigit = (l / (long) Math.pow(10.0, -s -1)) % 10;
                    if (roundDigit >= 5) {
                        l2 +=1;
                    result = l2 / Math.pow(10.0, scale);
                } else { //new scale is equal or greater than old scale
                    result = (l * Math.pow(10.0, s)) / Math.pow(10.0, scale);
                if (signum == -1) {
                    result = -result;
            }//else: Nan/Infinite => 0.0
            return result;
        }//getScaled()And even though it looks a bit scary, it make the whole application more than twice as fast (4 Minutes compared to 9 Minutes with the former BigDecimal scaling). As our app does lots of different calculations with lots of interim scaling and storing, this performance gain is quite surprising, as it shows that BigDecimal is not very usefull for massive math calculations ...

  • How to find inflection point in graph when dx is very small

    Hello,
    I'm trying to sort through position data from a feedback pot to calculate linearity of movement as part of a testing procedure. An image of the data is attached. I want to delete all data in the 'flat' part, in order to do a linear fit and R^2 of the sloped line.
    This is made trickier by the fact that the number of samples, the start and end points, and slope of the line can all vary considerably. Therefore I need some way to find the 'knee' in the graph and remove all subsequent samples from the data. 
    The most obvious method I tried was to use a derivative to find the inflection point, but since I have so many data points, the dx is very small
    (~0.05) when using the built-in labview derivatives. This means that I can't distinguish the inflection point from any other change in the values due to noise or change in velocity. I made my own derivative function, which was a newton quotient that looked at (xi+N)-(xi-N) instead of (xi+1) - (xi-1), but this still did not give good results. My next idea is to just look at the difference of every N points, and arbitrarily decide a threshold to indicate when it has levelled off. Any other ideas would be really helpful though.
    Thanks,
    -SK-
    Attachments:
    position.PNG ‏17 KB

    Lets see if I can answer without having to write a book.
    Fisrt I'd run the data through a zero-phase shift low pass filter. Then look at the 2nd derivative to find the knee. Using a zero-pahse shift fileter I was able to detect when a value was jumping up when it started to jump rather than after. THis thread may be interesting.
    Ben
    Ben Rayner
    I am currently active on.. MainStream Preppers
    Rayner's Ridge is under construction

  • The print in all the firefox menus (i.e. bookmarks menu, adress bar etc.)has gotten very small. How do i change it?

    Opened up my browser yesterday and all the print was very small in the firefox menus. the print on the sites i visit is large like it always was, this is just in the address bars, bookmarks and any other window .

    Try to disable hardware acceleration in Firefox.
    *Tools > Options > Advanced > General > Browsing: "Use hardware acceleration when available"
    *https://support.mozilla.org/kb/Troubleshooting+extensions+and+themes
    Current Firefox versions have support for HiDPI displays.
    You can set the layout.css.devPixelsPerPx pref to 1.0 or 1.25 (on Windows 8 the default DPI is 125%) on the <b>about:config</b> page (current default value is -1.0).
    *http://kb.mozillazine.org/about:config
    If necessary, adjust layout.css.devPixelsPerPx starting with 1.0 in 0.1 or 0.05 steps (1.0 or 0.9) to make icons show correctly.
    See also:
    *https://support.mozilla.org/kb/forum-response-Zoom-feature-on-Firefox-22
    Use an extension to adjust the text size in the user interface and the page zoom in the browser window.
    Use this extension to adjust the font size for the user interface.
    *Theme Font & Size Changer: https://addons.mozilla.org/firefox/addon/theme-font-size-changer/
    You can look at the Default FullZoom Level or NoScript extension if web pages need to be adjusted after changing layout.css.devPixelsPerPx.
    *Default FullZoom Level: https://addons.mozilla.org/firefox/addon/default-fullzoom-level/
    *NoSquint: https://addons.mozilla.org/firefox/addon/nosquint/

  • Trouble with site in flash should be visualized FULL  screen some people report to have seen very small

    REF.: trouble with site in flash that should be visualized in
    FULL screen as width/height parameters are set
    'width','100%','height','100%' - however some people report to have
    seen it very small as a “miniature”
    I simply cannot explain why some people report to see the
    flash site very small with Internet Explorer as I visualize it here
    in full screen.
    To be honest with Firefox 2 the same happens here , it does
    not open in full screen.
    I´ve pasted bellow the html source code employed ; The
    script is Adobe´s AC_RunActiveContent.js //v1.0
    Could someone please help me out ?
    Thank you
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0
    Transitional//EN" "
    http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="
    http://www.w3.org/1999/xhtml">
    <head>
    <meta http-equiv="Content-Type" content="text/html;
    charset=iso-8859-1" />
    <title> </title>
    <META NAME="description" CONTENT="">
    <META NAME="keywords" CONTENT="">
    <meta http-equiv="Content-Type" content="text/html;">
    <script src="scripts/AC_RunActiveContent.js"
    type="text/javascript"></script>
    <link rel="stylesheet" type="text/css" href
    ="giovannirocco_css/giovannirocco.css" />
    </head>
    <body>
    <div align="center">
    <script type="text/javascript">
    AC_FL_RunContent( 'codebase','
    http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=7,0,19,0','wid th','100%','height','100%','src','flash/giovannirocco_0','quality','high','pluginspage','h ttp://www.macromedia.com/go/getflashplayer','movie','flash/giovannirocco_0'
    ); //end AC code
    </script>
    <noscript>
    <object
    classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="
    http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=7,0,19,0"
    width="100%" height="100%">
    <param name="movie" value="flash/giovannirocco_0.swf"
    />
    <param name="quality" value="high" />
    <embed src="flash/giovannirocco_0.swf" quality="high"
    pluginspage="
    http://www.macromedia.com/go/getflashplayer"
    type="application/x-shockwave-flash" width="100%" height="100%">
    </embed>
    </object>
    </noscript>
    </div>
    </body>
    </html>

    Hey ! anyone to help me please ?

  • When I send image attachments through Mail they are received as very small and squashed. How can I change this?

    I have a problem sending image attachements (e.g., jpeg, png files etc) with the Mail utility from my MacBook Pro.  When people receive my email the attached image shows up not as an attached file that can be saved or downloaded, but as just a very small, squashed up version of the image imbedded in the email message itself.
    I usually add these attachments by simply dragging and dropping the desired file into the window of the email text. Is this the wrong way to do it?
    thanks
    Jerry

    Is this the wrong way to do it?
    The safest way to send images is to create a compressed file and send that.
    Click the image you want to send, go to File in the menu bar and select Compress... You end up with a file with a .zip at the end. Attach that to your email. Then trash the .zip file.
    The person at the other end only has to double click the .zip attachment.
    You can compress are single image or a folder of them.

  • How do i convert a float value to a double value?

    How do i convert a float value to a double value? HELP PLEASE!! im very stuck!! i gota float data type and i need to convert it to a double data type in order to use it in another operation.....
    thank u so much!

    safe dint realise ppl were so arrogant. thanks for the reply but less of the sarcasm!

  • Setting report to A4 has very smaller view in browser.

    Setting report to A4 has very smaller view in browser. How to set it to 1000px width and what are the limitations on printing if I use 1000px size.
    Help me regarding this.

    Hi Sanchit,
    In SQL Server Reporting Services (SSRS), it has two different rules in pagination: Physical pagination, Logical pagination.
    Physical pagination is used to the print control and the TIFF and PDF rendering extensions. It is controlled by the PageSize properties.
    Logical pagination is used to the HTML and GDI rendering extensions. It is controlled by the InteractiveSize properties.
    Reference:
    http://blogs.msdn.com/b/sqlforum/archive/2011/02/28/faq-how-do-i-get-the-same-page-number-in-web-page-and-pdf.aspx
    Did the printing point of view is the situation when we click Print Layout icon in preview report? If we click the icon, the default setting is fit the report of the whole report. We can change it to other value to get a more large view. Please refer to
    the screenshot below:
    If there are any misunderstanding, please feel free to let me know.
    Regards,
    Alisa Tang
    If you have any feedback on our support, please click
    here.
    Alisa Tang
    TechNet Community Support

  • How can I limit a double value to two decimal place?

    How can I limit a double value to two decimal place?
    Java keeps on adding zero's to a simple double subtraction:
    1497 - 179.64 = 1317.3600000000001The answer must have been simply: 1317.36

    If the trouble is with output ...
    If the trouble is with value accuracy ...The trouble is with OPs understanding of and/or expectations of IEEE 754 floating point numbers. o_O
    [And it's probably a view (output) issue.]
    how can i actually use numberformat to cut those
    unwanted decimal places?Read the API - Puce already provided the link.

  • Email text size suddenly very small, uncontrolled font change

    Without warning, the text of incoming emails is suddenly very small.  The body of text is crowded into the left side of the screen.  And, old emails in the inbox are exhibiting the same behavior.  If you double tap the text, it resizes to fill the screen, but you shouldn't have to double tap every message to get it to read properly.  I have tried accessibility function and increased the font size, but that has not helped.  Reading email in landscape helps.   I recently turned on iCloud but then turned it off with respect to emails.  Cannot figure out why this is suddenly happening.   Help.

    Try quitting Mail.
    Go to the Home screen and double click the Home button. That will reveal the row of recently used apps at the bottom of the screen. Tap and hold on the Mail app until it wiggles and displays a minus sign. Tap the minus sign to actually quit the app. Then tap anywhere on the screen above that bottom row to return the screen to normal. Then restart the app and see if it works normally.

  • Summing of double values

    Hello everybody, i have a problem summing double values got from JFormattedTextFields, i need to make it somehow shorter, i couldn't find such function as Math.sum or something like that, with bold i selected problematic area - if i had somewhere 100 formattedtextfields it would be a serious problem! Thanks!
    package Array;
    import java.text.NumberFormat;
    import javax.swing.JFormattedTextField;
    +public class Array extends javax.swing.JFrame {+
    JFormattedTextField[] tekstalauks;
    NumberFormat JFTFformats;
    NumberFormat SummaFormats;
    double[] vertibas;
    int vDaudzums=10;
    int daudzums=10;
    int y=-15;
    +/** Creates new form Array */+
    +public Array() {+
    Formats();
    initComponents();
    +}+
    +public void PirmaDala(){+
    +tekstalauks=new JFormattedTextField[daudzums];+
    +double[] vertibas=new double[vDaudzums];+
    for(int a=0; a<tekstalauks.length; a+){+
    y=y25;+
    +vertibas[a]=0;+
    +tekstalauks[a]=new JFormattedTextField(JFTFformats);+
    +tekstalauks[a].setValue(new Double(vertibas[a]));+
    +tekstalauks[a].setBounds(10, y, 40,20);+
    +jPanel1.add(tekstalauks[a]);+
    +}+
    +}+
    +public void Formats(){+
    JFTFformats=NumberFormat.getNumberInstance();
    SummaFormats=NumberFormat.getNumberInstance();
    +}+
    +private double Summa(double vertibas[]){+*
    double atbilde=0;*
    atbilde=((Number)tekstalauks[0].getValue()).doubleValue()((Number)tekstalauks[1].getValue()).doubleValue();+*
    return atbilde....;*
    +}+
    +private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {+                                        
    +// TODO add your handling code here:+
    double sum=Summa(vertibas);
    Summa.setValue(new Double(sum));
    +}+
    +public static void main(String args[]) {+
    +java.awt.EventQueue.invokeLater(new Runnable() {+
    +public void run() {+
    new Array().setVisible(true);
    +}+
    +});+
    +}+

    Hi, problem is - i have for example 100 JFormattedTextFields generated on JPanel (this is already working)
    I have one field where result is showing named Summa. Result is sum of each jformattedfield (total count 100) value - in bold this is example of just two first fields, couse it would be very annoying to write for all 100 fields, i need to know- how can i make to sum from all fields using just few lines of code!

  • Funny question on double value

    hi all,
    I have a rather funny question ...
    how to getrid of the E from a very huge double number without using the java.math.BigDecimal or java.math.BigInteger classes.
    ex:-
    Double d1 = new Double("1487194731984573985734095734905873059734059734957340958734957309457389457983475");
    Double d2 = new Double(d1.doubleValue() * d1.doubleValue());
    d2.doubleValue() will give 7.246073001982964E147
    but the result should not have the E but the complete value.
    the thing is not to use java.math package.
    thx
    chandra

    Well you can use java.text.DecimalFormat to format the output of a double value. However you'll find that the huge value you think you stored in the Double is not in fact what java has kept - double does not have the precision you have requested and using the DecimalFormat this will be evident... EG doing something like
    double d = 123456789012345678901234567890.0;
    DecimalFormat df = new DecimalFormat(
    System.out.println("123456789012345678901234567890.0");
    System.out.println(d);
    System.out.println(df.format(d));Should clearly show that the value stored has lost precision. The reason you do not get an overflow as with an int value is that the values scale can be represented in the double not its precision.
    Hope that helps...
    Talden

  • How to solve NaN error, while dealing with multiplication of double values

    i am getting NaN error in the program.
    consider this following code
    for (j=0;j<nh;j++)
    sum = 0.0;
    for (i=0;i<ni;i++){ sum = sum + (ai[i] * wi[i][j]) ;}
    //System.out.println(sum);
    ah[j] = sigmoid(sum);
    public static float sigmoid(float x)
    return ((Math.exp(x)- Math.exp(-x)) / (Math.exp(x)+Math.exp(-x)));
    ni = 2500-- no of input nodes;
    nh = 5000 -- no of hidden nodes;
    i am getting problem in calculating the "sum" value. its returning NaN for "sum".
    here a[i] values are around some +/- 0.XXXXXXXX upto 14 digits
    and wi[j][j] values are also +/- 0.XXXXXX upto 14 digits.
    all values are of datatype double.
    i was stucked up with this problem. what i am to do?
    give me suggestions..
    please reply me

    This can occur with double divisions. I wrote a small method that solves this:
         * Set double values that have a value of 'NaN' or 'Infinity' to 0.0. This can happen when dividing double values as they
         * don't cause a DivisionByZeroException.
         * @param value Double value to check.
         * @return Input value with 'NaN' and 'Infinity' set to 0.0.
        static public double resetNaN(final double value, final double resetValue) {
            return (Double.isNaN(value) || Double.isInfinite(value)) ? resetValue : value;
        }//resetNaN()

  • Unable to display double values in Excel sheet using JExcel API

    Hi
    I am writing code to generate report in the form of Excel Sheet using JExcel API.
    Everything is going fine but whenever I want to put some double values in a cell it is only showing 2 decimal places. My problem is "I want to show upto five decimal places".
    Any kind of reply might help me lot.
    Thank U.

    If you enable the submit zero option, it still happens? This is a new feature on the display tabl
    #NumericZero Enhancements
    To display a numeric zero in place of an error message, you can enter #NumericZero in any of the three Replacement text fields. When you use the #NumericZero option:
    · Excel formatting for the cell is retained.
    · All calculations with dependency on the cell will compute correctly and will take the value of this cell as zero.
    · This numeric zero is for display only. When you submit, the zero value is NOT submitted back to the data source.
    You cannot set display strings for cells that contain an invalid member or dimension name (metadata error). Metadata errors produce standard descriptive error messages.
    Errors are prioritized in the following order from highest to lowest. The error message for a higher-priority error takes precedence over that for a lower-priority error.
    1. (Highest) Metadata errors
    2. #No access
    3. #Invalid/Meaningless
    4. #No data\Missing

Maybe you are looking for

  • No more free item numbers (Please check)

    Dear Experts , We are in a process of upgradation and during Unit testing I am facing a issue for which i require your suggestions. While Converting the Planned order to prod Ord in CO40 every thing is ok except when i check in component overview i g

  • Tuning an optical encoder with a linear actuator

    Hello everyone! I am trying to get an optical encoder (5 lead single ended, incorperated into an Ultramotion D2 series linear actuator) to read the position of the linear actuator's position to 4 decimal figures precision (0.0001), and the DAQ I am u

  • 5400 ROM & 7200 RPM HD's

    I hope this is the right place to post this. I have a 250GB 5400 RPM HD in my Macbook Pro. I want to replace it with the biggest HD I can find. I think I will get a 500GB or a 400GB @ 7200RPM. What I was wondering is if you guys think that the 7200RP

  • Oracle Discoverer: How to handle null value

    In Oracle Discoverer, I pull data from a folder. When I hit Null value for a column, I want to replace it with data from another folders column. Something like the functionality of "nvl" of a SQL statement. How can I do the following query in Discove

  • CommandButton and commandLink strange behaving

    I use <h:commandButton value="ok" action="{#bean.method}"/> bean.method returns null to stay on same page. when I run it on localhost everything is OK. when I deploy application on server, then action method is never called and nothing is happend (ne