Approximate equality

Sorry to clog the boards with my question but I've exhausted all other avenues of research. I have a program that recursively generates the powers of a number. Base x to the nth power. The numbers that this program generates are sometimes large and when comparing them to the oracle I am using even slight differences between them are causing my if statement to fail. Its there a method by which I can test two very large or small numbers to an approximated level of equality? I've though about parsing my outputs to a string loop with a charAT() method to go number by number but I think there might be a better way.
Also, I am student and this is my first time posting in the boards so if I have placed my post in the wrong place please feel free to /flame and I'll remove it immediately.
Thank you in advance to everyone for your assistance.
// tester
public class RecursivePowerTester {
public static void main(String[] args) {
     int qq=0,correct=0,x=15,n=19;
     double g;
     double oracle;
     System.out.println("This program will solve for X^n power");
while (qq<10000)
x = 1 + (int)(Math.random() * 20); // random number casted to int between 1-20
n = 1 + (int)(Math.random() * 10); // random number casted to int between 1-10
RecursivePower z = new RecursivePower(x,n);
g = z.getPow(x,n);
     oracle = Math.pow(x,n);
     if (g==oracle)
          correct++;
     else
               System.out.println("My recursive method " + g + " Math.pow() oracle " + oracle + " x " + x + " n " + n + "howclose" + Math.abs(oracle - g));
     qq++;
     System.out.println("Out of " + qq + " operations the oracle and the recursive method had identical values " + correct + " times");
public class RecursivePower {
public RecursivePower(int xx, int nn) {
          x=xx;
          n=nn;
// self calling recursive method that multiplies the base to satisfy the nuber of powers
public double getPow(int x,int n)
if (n ==0)
return 1;
else return x * getPow(x,n-1);
private int x;
private int n;
}

This is my code at the moment:
//tester class
public class RecursivePowerTester {
public static void main(String[] args) {
RecursivePower z = new RecursivePower();
     int qq=0,correct=0,x=15,n=19;
     double g;
     double oracle;
     System.out.println("This program will solve for X^n power");
while (qq<10000)
x = 1 + (int)(Math.random() * 90); // random number casted to int between 1-90
n = 1 + (int)(Math.random() * 90); // random number casted to int between 1-90
g = z.getPow(x,n);
     oracle = Math.pow(x,n);
     if ((g==oracle) ||(Math.abs(g-oracle) < Math.abs((oracle-(oracle*.999999999999998)) )))
          correct++;
     else {
               System.out.println("My recursive method " + g + " Math.pow() oracle " + oracle + " x " + x + " n " + n + "howclose " + Math.abs(oracle - g));
     qq++;
     System.out.println("Out of " + qq + " operations the oracle and the recursive method had identical values " + correct + " times");
// recursive method class
public class RecursivePower {
public RecursivePower() {
// self calling recursive method that multiplies the base to satisfy the number of powers
public double getPow(int x,int n)
if (n ==0)
return 1;
else return x * getPow(x,n-1);
}

Similar Messages

  • Is it possible to set the precision for the subtraction operator?

    Hi everyone.
    I have two complex double precision numbers that are suppose to be equals. Each one is the result of different sets of equations.
    When I subtract one from the other the result is not zero.
    I think this can be explain by the fact that they are quite large numbers (about 1E+101), causing the subtraction operator to drop (or round, or do something not legit with) the two numbers. Moreover, if I repeat the subtraction with different large numbers, I obtain about half of the time the expected result (zero) and the rest of the time I obtain a value between 1E+84 and 1E+86.
    What I would like is to get the result right everytime, so I thought about setting a precision to the subtraction operator. Is that possible? If it is, how am I suppose to do that and if not, what's wrong with the subtraction operator?
    Thanks
    tonh

    Thought 1: 1e+101 is pretty big!  Do you *need* all your calcs to carry such a big exponent?  For example, can you run all the calcs on values that have been scaled by 1e-100, then at the end of all the calcs scale back by 1e+100? 
    Thought 2: If you just need to compare for approximate equality, you could divide the difference by the larger of the two values being subtracted.  If you subtract two virtually equal 1e+101 values, you may get a difference in the order of 1e+85.   The division will give you a ratio of ~1e-16.  Ratios in that realm will mean that the two original values are about as nearly equal as the floating point representation can express.   This type of method scales pretty well to work with both very small and very large floating point numbers.
    Thought 3: If the inputs to your calcs are in the order of 1e+85 or less, you may really have your work cut out for you.  You'll need to think carefully about floating point representation error at each step of the calculations to know where you can round, truncate, approximate, etc.  There may be places where rounding will be *necessary* and other places where it is *disastrous*.
    To summarize: you need to apply some of your error knowledge to your code.  The 1e+101 calculated values probably don't have more than 6-8 *significant* digits of accuracy, right?  (Most numbers come from some kind of measurement, or a rounded-off value for a scientific constant, etc.)  You'll need to analyze your values and calcs to understand about how many digits of the 1e+101 numbers are truly *significant*.  Then your code will need to treat values which differ by less than that amount as if they are truly equal.
    -Kevin P.

  • Basic color management questions

    Having difficult understanding some concepts in color management - would appreciate any guidance to further understand it.
    What is the difference in backgrounds between additive and subtractive process color systems?
    How is white formed differently in additive and subtractive process systems?
    How are the non-process colors like orange formed differently in the additive and subtractive process systems? What colors from each system forms an orange?
    Why is the difference in the process of color formation of major concern with the use of computers in the preparation of materials for 4-color process color printing?
    Why is the difference in the process of color formation of major concern with the use of computers in the preparation of materials for 4-color process color printing?

    Sarah,
    Deep subject, so this will only touch the surface.
    What is the difference in backgrounds between additive and subtractive process color systems?
    How is white formed differently in additive and subtractive process systems?
    RGB blends "light" to generate colors.  CMYK blends "inks".  Starting with RGB and light.....pure white blends high levels of red, green and blue wavelengths in approximate equal amounts, which we perceive as white.  In Photoshop parlance, using 8-bit, this translates to 255R, 255G, 255B.  When we see an object, we are actually seeing the light that reflects from that object, not the object itself.  So, a bright white object reflects most of the visible light spectrum and reaches our eye, which the brain interprets to be white.  A black object "absorbs" light so nothing is reflected to the eye.
    To print, you need inks on paper, not light.  If you were to use red, green and blue inks, you'd have a big problem printing colors like yellow.  So, they devised the subtractive color process (RGB is additive, ie, adding all three lights together gives you white).  They took the opposite colors of Red, green and blue, which are Cyan, Magenta and Yellow.  In theory, you should be able to create the same spectrum of colors with the CMY subtractive colors that you can with the RGB additive colors, but in practice, that is not the case, for at least two reasons.  The CMY inks are not pure and as intense as the RGB primaries, and second, you have to apply these inks to paper, which drastically limits dynamic range.  To deal with the ink purity problem, (and to give better type), they add Black to the CMY mix, for four inks....Cyan, Magenta, Yellow, and Black.  To get white, you rely on the paper alone, without any ink.  In theory, pure black would be either 100C, 100M, 100Y, or it could be 100K (black), or it could be 100% each of CMYK.  But, these three do not give the same results, due to ink purity, ink limits,  paper, process, etc.
    How are the non-process colors like orange formed differently in the additive and subtractive process systems? What colors from each system forms an orange?
    Why is the difference in the process of color formation of major concern with the use of computers in the preparation of materials for 4-color process color printing?
    In the CMYK world, orange is a mixture of Yellow and Magenta inks, with more yellow than magenta.  For example, 52M, 94Y gives a fairly vibrant orange.  Again, hue, saturation and brightness are dictated by the mix percentages, paper, ink limits, ink purity, etc.  In the RGB world, this same color is defined as 255R, 143G, 33B (depending on the "flavor" (color spaces) of RGB and CMYK you are using.  There is a relationship between RGB and CMYK, and this example is no exception.  When red is maxed out at 255, cyan is the opposite, in this case zero.  In this orange color, Green is 143, near the middle of the range, and so is its opposite, Magenta, which is near the middle of its range, at 52.  Blue is 33, at the very low end of its range, and its opposite, Yellow, is near the top of its range at 94.  Since this is a bright color, there is no black ink used at all.  If it were a darker orange, there would probably be some black in as well.
    Some colors can be created in RGB that cannot be duplicated in CMYK.  The opposite is also usually true, that there are colors in CMYK that cannot be duplicated in RGB (depending on the color space you use).  If your intended output is a monitor, the internet, email, or a printer that needs "light" you would generally use RGB.  If the intent is to "print" the job, on a press, inkjet, laser, etc, then CMYK is generally used.  Even if you send an RGB file to your inkjet, the printer driver translates the RGB colors to CMYK in the background before output.  Most, if not all, printers use CMYK subtractive inks for printing,  These can generate a large portion of the printable spectrum.  Some printers add light cyan and light magenta inks, or even red, green, blue, orange, and other colors to help extend the color gamut of the printer so it can achieve colors that would be "out of gamut" using CMYK alone.
    Another difference is that CMYK is a four color process, unlike RGB, which is three color.  A given color has only ONE definition when defined in RGB, HSB, L*a*b*, or other 3 component color schemes.  With CMYK, many colors can be created using different mixes of CMYK, which adds complexity, but also offers opportunities and flexibility, especially on press.
    Like I said at the beginning, this is a very deep and complex subject, and this only touches on the basics.
    Lou

  • ORA-20011: Approximate NDV failed: ORA-29913: error in executing ODCIEXTTAB

    Hello All,
    I am using Oracle 11.2.0.3
    in my alert logs I found the below errors:
    ORA-20011: Approximate NDV failed: ORA-29913: error in executing ODCIEXTTABLEOPEN callout
    KUP-11024: This external table can only be accessed from within a Data Pump job.to resolve that i did the below steps:
    SELECT owner_name, job_name, operation, job_mode,
    state, attached_sessions
    FROM dba_datapump_jobs
    WHERE job_name NOT LIKE 'BIN$%'
    ORDER BY 1,2; the result was that there is two running jobs and the attached_session flag was equal to 1, something like the below:
    OWNER_NAME JOB_NAME            OPERATION JOB_MODE  STATE       ATTACHED
    SCOTT      SYS_IMPORT_TABLE_05      IMPORT TABLE RUNNING        1
    SCOTT      SYS_IMPORT_TABLE_01 IMPORT TABLE     RUNNING        1 so i stopped these 2 jobs using the below statements:
    SET serveroutput on
    SET lines 100
    DECLARE
       h1 NUMBER;
    BEGIN
       h1 := DBMS_DATAPUMP.ATTACH('SYS_IMPORT_TABLE_05','SCOTT');
       DBMS_DATAPUMP.STOP_JOB (h1);
    END;
    SET serveroutput on
    SET lines 100
    DECLARE
       h1 NUMBER;
    BEGIN
       h1 := DBMS_DATAPUMP.ATTACH('SYS_IMPORT_TABLE_01','SCOTT');
       DBMS_DATAPUMP.STOP_JOB (h1);
    END;
    /now the result become like below as stop pending in the state column:
    OWNER_NAME JOB_NAME            OPERATION JOB_MODE  STATE       ATTACHED
    SCOTT      SYS_IMPORT_TABLE_05      IMPORT TABLE STOP PENDING 1
    SCOTT      SYS_IMPORT_TABLE_01 IMPORT TABLE     STOP PENDING 1 for that I did more research and i dropped two temporary external tables after I got their names using the below query:
    select OWNER,OBJECT_NAME,OBJECT_TYPE, status,
    to_char(CREATED,'dd-mon-yyyy hh24:mi:ss') created
    ,to_char(LAST_DDL_TIME , 'dd-mon-yyyy hh24:mi:ss') last_ddl_time
    from dba_objects
    where object_name like 'ET$%'
    /but nothing changed in the output of the below query, the state stayed STOP PENDING
    SELECT owner_name, job_name, operation, job_mode,
    state, attached_sessions
    FROM dba_datapump_jobs
    WHERE job_name NOT LIKE 'BIN$%'
    ORDER BY 1,2; for that I used stop job but with the immediate flag as 1
    DBMS_DATAPUMP.STOP_JOB (h1,1); now the result of the query is NOT RUNNING in the state column:
    OWNER_NAME JOB_NAME            OPERATION JOB_MODE  STATE       ATTACHED
    SCOTT      SYS_IMPORT_TABLE_05      IMPORT TABLE     NOT RUNNING   0
    SCOTT      SYS_IMPORT_TABLE_01      IMPORT TABLE     NOT RUNNING   0 and I discovered that one of my import jobs that I did not realize that it was running, failed due to a fatal error, it is the one related to the import of one table.
    My question:
    Now the below query should return zero records no ?
    How i can clear the result ? and does it affect any future import jobs for the same table?
    SELECT owner_name, job_name, operation, job_mode,
    state, attached_sessions
    FROM dba_datapump_jobs
    WHERE job_name NOT LIKE 'BIN$%'
    ORDER BY 1,2;

    hi just drop all tables that return be the query below i face some issue after 1 months
    SQL> select owner, TABLE_NAME, DEFAULT_DIRECTORY_NAME, ACCESS_TYPE
    from dba_external_tables
    this error appear due to this table must be cleanup auto when the datadump complete the job ,but it's not dropped as well so when gather statistics this error appear,
    so this drop table .

  • Is not equal to operator not working properly in obiee 11g

    Hi ,
    I have 5 members in a dimesion ENTITY.gen5 (A,B,C,D,E) .
    nOW , I am using a *"is equal to "* operator in that ,
    ENTITY.gen5 = A;B .
    Which results in a strange error while running the report :
    Socket communication error : was attempted on somthing which is not socket .
    or sometimes ,
    Socket communication error : Oracle BI server is not currently running .
    So , I tried with giving "is not equal to" i.e . ENTITY.gen5 != C;D;E .
    Then , I am getting A,B,C . C is not desired here .
    FYI , I have renamed ENTITY.gen5 member names in essbase once and after refreshing I tried the above .
    OBIEE version : 11.1.1.6
    essbase version : 11.1.2.1
    Thanks in advance

    In EM, go to Weblogic Domain, right click on bifoundation_domain and on the Security menu choose Application Policies.
    Set Application Stripe to obi and click the blue arrow search button.
    Highlight BIConsumer and click Edit.
    Under Permissions locate Resource Name oracle.bi.publisher.scheduleReport. Highlight this and click Delete...
    Click OK (top right corner).
    Now log your user out of OBIEE and back in again, and the option should have disappeared from their New menu.

  • Price condition equal to VPRS cost of goods

    I have a senario ,which we will create sales orders for customers with sales price equals to the MAP(moving average price) at the  time when the SO being input .And the sales price in sales orders should be copy to the billing whether  the MAP has changed or not .
    Now I have set up an pricing procedure ,which  use  VPRS  as the sales price condition type ,but here comes another question when I create billing according to the delivery . When I create the billing document ,the net value is defferent with the net value of the sales order ,because the MAP has changed during the goods issue.
    Is there any idea that can make sure the sale price equals to the MAP , and the billing net value is same as sales order net value?
    can you give me some advice ? thanks for you help!

    Hi,
    The pricing type (Copy control)  is an extremely important field. It is worthwhile keeping this entry
    in mind when creating your pricing condition types. As a rule of thumb, you should
    have all item categories for a particular sales document with the same settings.
    Generally, you may use pricing type B (carry out new pricing), G (copy pricing
    elements unchanged and redetermine taxes), or C (copy manual pricing elements
    and redetermine the others).
    When using condition B all manual pricing condition types are lost.
    If you want to copy the sales order to the invoice without changing the sales order
    conditions, use pricing rule G. This will copy the pricing conditions from the order into the
    invoice without changing them, but will redetermine the taxes.
    Regards...
    SBC

  • F8 Pro Forma for free goods - value in F8 line item to equal VPRS cost

    Hello,
    I would like to configure the following scenario:
    FD sales order created with KLN item category
      LF delivery created and processed
      F2 billing invoice created (no charge)
      F8 pro forma invoice created (line item value to equal line item cost)
    I have already configured this to work properly for regular sales orders and the values copy from the order as specified in the VTFL copy control settings, but I can't figure out how to get the above situation working.  Any help would be greatly appreciated.
    Thanks,
    Andy

    Check OSS Note 33258 - Processing free-of-charge items is of help to your scenario.
    Regards,

  • Microsoft Service Pack 2 - not all versions are equal; how to update to the latest one "safe

    I posted this under another topic where it was relevant, but thought the instructions I got from Microsoft were useful (as was my experience in using them as I sent back a reply to them with the problems I encountered [none of which were particularly bad]):
    One important point to note is that not all Windows XP SP2 upgrades are equal.
    I had a different issue and spoke to Microsoft, who advised me to uninstall the version of SP2 I had and reinstall the newest version (the old version was about 70mb, the new one nearly 250mb).
    Apparently the old SP2 had quite a few problems with it; I've found the new one to be "simply stress free" since installing...
    The SP2 file name I installed (ie the newest at the time I did it) was "windowsxp-kb835935-sp2-enu".
    Here's their instructions - I disagree with the way round that they suggested downloading the update (ie I would strongly advise downloading the update and having it sitting on your desktop before doing anything!!! - please see my feedback email to them that follows (you will note that I had problems connecting to the internet after uninstalling the earlier version; this, combined with the fact that I could barely read what was on the screen would have given me a major inconvenience had I not done this)!!! (and don't blame me if it goes horribly wrong - it's also worth double-checking that the version of SP2 the email links to is the most up to date. I've had a quick check myself, and it does indeed appear to still be the most up to date):
    MICROSOFT'S EMAIL (make sure you also read my reply below):
    MESSAGE:****************************************** ****************************This is an email from Microsoft about your support incident.When replying to this address: + It helps us if you do not include the original message + Please keep the case number (SRxxxx) in the subject lineThank youMicrosoft Product Support Services ******************* The message from Microsoft follows ****************Hi Gregory,Firstly uninstall SP2 by going to Start>Control Panel>Add/Remove Programs and then reinstall it in a clean boot.. Click Start >> Run >> In the run dialog box type msconfig and then click ok 2. Put a dot in selecti've startup 3. Uncheck all of the check boxes that become available except Process System.ini file and Load system services 4. Go to the Services tab along the top, click Hide all Microsoft Services 5. Then disable any remaining services 6. Click apply and then close 7. Finally select yes, this will start in a clean boot. 8. Then go to (http://www.microsoft.com/downloads/d...DisplayLang=en) and download and install Service Pack 29. To return your PC to normal, open the System Configuration Utility, click "Normal Startup", click OK and restart. Then restart your computer and try accessing updates againPlease let me know the results of these methods, particularly if there were any steps that you were unable to complete successfully.
    MY REPLY:
    HiI successfully carried out the installation on Saturday.A few minor problems ensued (the second one may have cause a novice user real problems! Certainly caused me some concern whilst working through it!). I had to reinstall ATI drivers from scratch (for Radeon 9800 Pro); this was however the only set of drivers that appeared to "detach" itself. The main problem here was that instead of using the usual standard VGA driver (which it does when I uninstall it once a month to install updated drivers), it used some other driver that made the screen very difficult to see (especially on blue backgrounds!). Running ATI's total uninstall program sorted this out however, and fortunately I had the last update package from ATI still on my system. After uninstalling and reinstalling there appeared to be no further video problems.2. After installing SP2 (and before installing above), whilst I was in the process of getting everything up and running (eg installing the security updates) the system randomly froze about 4 or 5 times; the only way to sort this out was to use the power button. I traced this problem to Windows changing my wireless networking settings so that it handled everything; I have a Netgear adaptor the software for which usually controls this (Netgear Smart Wizard). Basically the two were trying to do the same task and causing crashes; on switching Windows management off, things settled down (the Netgear driver did not need to be reinstalled).3. As a minor point, after the upgrade and installing all other updates, I noted that Microsoft Update was no longer running; I had to reinstall it from Windows Update and the messages I got whilst installing suggested that it was still partially installed but that there were problems with it. It now works.4. As a final minor point, I attach the Scan log from Registry Mechanic which I ran after everything was up and running; it fixed various problems within the registry. I note that the majority of errors are inconsequential, but note that a few do relate to the various Microsoft installs; maybe the installer program for SP2/ Media Player 0 need to sort these out in future releases? Don't think they're a real problem though!The instructions supplied worked fine; one thing I would suggest is that users are instructed to download the SP2 upgrade pack to their desktop prior to uninstalling the original SP2; I believe that my internet connection problems started after I had uninstalled the original SP2 which may have caused problems downloading the new SP2. It also ensures that the download is successful (eg if the site was down for maintenance); I was advised whilst uninstalling SP2 that about 20 programs/drivers would not work properly after the uninstall and so the immediate reinstall was vital!One thing that seemed to fix after reinstalling was a problem I was having installing Media Player 0; after installing it previously, every time I checked for updates on it the whole program would reinstall. Now however this has fixed. I will let you know if I encounter any further problems, but things all seem to be fine now, touch wood.....!
    Hope this helps!Message Edited by gjc26 on 0-27-2006 02:50 AM

    One small thing - I believe the reason why some of my drivers were messing up was because they were SP2 specific; the older drivers and the ones that were compatible with both SP and 2 were fine.
    As soon as I did the reinstall, all of the drivers/programs that were not working, worked (aside from the ones that I mentioned in my attached email above).
    So, if after uninstalling the old SP2 you are told that loads of drivers/programs will not work, fear not - most should fix themselves upon installing the new SP2.
    G

  • What is difference between == and equals ??? i wanna know in detain example

    Hi
    1) String s1 = new String("abs");
              String s2 = s1;
              System.out.println(s1==s2);
              System.out.println(s1.equals(s2));
    Output:
    true
    true
    2)
    String s1 = new String("abs");
              String s2 = s1;
              s2 = "abs";
              System.out.println(s1==s2);
              System.out.println(s1.equals(s2));
    output:
    false
    true
    i m not getting that here s1 is object and its assigned to s2 object so both are point to same memory location...but while assinging s2 = "abs" which is same as s1 then its behave like different object y?

    but while assinging s2 = "abs" which is same as s1 then its behave like different object"abs" is "the same as" s1 in the sense that it represents the same characters in the same order. But it is also different from s1 in that it refers to a different object. It's the same distinction as you get comparing two $20 notes: they are equal but, since there are two of them they cannot be identical.
    With Java reference variables this equal/indentical distinction is represented by equals()/==.
    In general each class defines its own equals(). (Much as there will be a legal definition what what counts as being equal to $20.) This realationship is generally what you mean and hence the rule "when comparing objects use equals()".

  • The initial heap size must be less than or equal to the maximum heap size.

    All,
    Please help!!
    I have tested my Application Client Project in WSAD on my pc and it works fine.
    I have 1gb RAM on my pc. When I deploy the same app on another xp pc(same as mine but 512mb RAM) I get a heap size error. Here is the exact error:
    Incompatible initial and maximum heap sizes specified:
    initial size: 268435456 bytes, maximum heap size: 267380736 bytes
    The initial heap size must be less than or equal to the maximum heap size.
    The default initial and maximum heap sizes are 4194304 and 267380736 bytes.
    Usage: java [-options] class [args...]
    (to execute a class)
    or java -jar [-options] jarfile [args...]
    (to execute a jar file)
    where options include:
    -cp -classpath <directories and zip/jar files separated by ;>
    set search path for application classes and resources
    -D<name>=<value>
    set a system property
    -verbose[:class|gc|jni]
    enable verbose output
    -version print product version
    -showversion print product version and continue
    -? -help print this help message
    -X print help on non-standard options
    Could not create the Java virtual machine.
    Press any key to continue . . .
    Here is the batch file that runs my app:
    @echo off
    SET appClientEar=C:\corp\apps\mts\jars\MTSClientEAR.ear
    set JVM_ARGS=-Xms256M -Xmx256M
    set CLIENT_PROPS=C:\corp\apps\mts\jars\medicalclient.properties
    set APP_ARGS=
    call C:\bnsf\IBM\WebSphere\AppClient\bin\launchClientBNSF.bat "%JVM_ARGS%" %appClientEar% "-CCpropfile=%CLIENT_PROPS%" %APP_ARGS%
    @pause
    I have changed the value of Xms and Xmx of JVM_ARGS to different size but I sitll get error. Anyone knows what the problem is. Thanks..

    Don't know why, but the "maximum heap size: 267380736 bytes" value is just slightly less than 256*1024*1024, wheras the reported initial size is equal to that.
    Try setting the initial value to 255MB.

  • I have a Macbook Air that had some coffee spilled on the keyboard and as a result the plus/equals key is no longer functioning. Can I use a program like Ukelele to reprogram a different key to be my plus/equals key? Can I program a function key? key

    I have a Macbook Air that had some coffee spilled on the keyboard and as a result the plus/equals key is no longer functioning. Can I use a program like Ukelele to re-program another key to do that function? Can I re-program a function key to do this function?

    Water + electronics do not mix.  Something was damaged insode, and the logic board may be corroding as is.
    Take it to a Genius Bar for an evaluation and repair estimate.
    This is accidental damage and not covered by warranty.

  • Null values not equal

    I'm writing some reports that are pulling possible duplicates out of a table. I have to base the query on several nullable columns in my table. I was tired of writting (a.column1 = b.column1 or (a.column1 IS NULL and b.column1 IS NULL)) for every column being compared so i wrote the following function:
    CREATE OR REPLACE FUNCTION equivalent (
    in_one     VARCHAR2,
    in_two     VARCHAR2)
    RETURN NUMBER IS
    BEGIN
    IF in_one = in_two THEN
         RETURN 1;
    ELSIF in_one IS NULL AND in_two IS NULL THEN
              RETURN 1;
    END IF;
         RETURN 0;
    END equivalent;
    Now I just pass equivalent(a.column1, b.column1) = 1. The problem is that this seems to take considerably longer. Does anybody know why or have a suggestion to speed things up?
    Any help would be appreciated.
    Thakns in advance,
    Chris S.

    There is always an overhead to calling PL/SQL. If you're running on 9i you could try compiling your function as native C; that way it will run almost as fast as kernel code. If you want to save yourself a bit of typing you could try this:
    nvl(a.column1, 'Chris is ace!!') = nvl(b.column1, 'Chris is ace!!') Of course, you need to substitute some more buisness-like but equally non-valid phrase for 'Chris is ace!!'
    - er - if you know what I mean. And it still won't use any indexes.
    Cheers, APC

  • Difference between .equals("") and .equals(null)

    Can any one please tell me the difference between the following?
    String someString;
    someString = someMethod(someParameter);
    After the method call, if I am going for a check like this..
    what will each check do?
    1. if (someThing.equals(null))
    2. if (someThing.equals(""))
    3. if (something == null )
    4. if (something == "" )
    Thanks in advance,
    Regards
    Rakesh

    First, understand that the empty string ("") and null are two very different things. The empty string ("") is a string object that just doesn't contain any characters. It's still an object though--you can call it's methods.
    Null, on the other hand, is essentailly nothing. It's a special value that means "Nothing. No object here." (Ignoring for now the distinction among the null type, a null reference, etc.) You can't call methods or refer to fields on null. If you try, you'll get a NullPointerException.
    1. if (someThing.equals(null))Calls the equals method on someThing to compare someThing to null. If someThing is not null, this returns false. If someThing is null it... what? returns true? Nope. Throws NullPointerException. You can't call the equals method on a null someThing.
    Therefore there's no point in ever using equals(null).
    2. if (someThing.equals(""))Calls the equals method on someThing to compare someThing to the empty string (""). If someThing is not null, but is empty, it returns true. If someThing is non-null and is not empty (e.g., "abc"), it returns false. If someThing is null, it throws NPE.
    One generally uses the equals method, not the == operator to compare objects--that is, to see if their contents or states are equal. The == operator is used to see if two referecnes refer to the same object, or if a reference is null.
    3. if (something == null ) Evaluates to true if something is null and to false if something is non-null. Never throws NPE (since we're not calling a method or accessing a field).
    4. if (something == "" ) You never really want to use == to compare a String variable to a String literal like this. This checks to see if the reference something is referring to the same object as the "" is. The "" will be referring to an object in the constant pool. Even if something is the empty string, it may not refer to the same entry in the constant pool.
    That is (something == "") could evaluate to false, but something.equals("") could return true.

  • Not Equals Function is not working in Mapping

    Hi All,
    i have to do mappig based on the Not Equals & And conditions
    If the Material Group starts with "F"
                            And Material Type Not Equals to "ZPRO" means
                                        then send "FG" Else "FC"
    Here Not Equals & And Functions are not giving success, Error throwing like
    Cannot cast ZPRO to boolean] in class com.sap.aii.mappingtool.flib3.Bool method not[ZPRO
    Please help in this
    Regards

    i have to do mappig based on the Not Equals & And conditions
    If the Material Group starts with "F"
    And Material Type Not Equals to "ZPRO" means
    then send "FG" Else "FC"
    Here Not Equals & And Functions are not giving success, Error throwing like
    Cannot cast ZPRO to boolean] in class com.sap.aii.mappingtool.flib3.Bool method not[ZPRO
    the logic applied is incorrect
    NotEquals is a boolean function meaning it will accept only boolean values as input....
    To check if the Material Number is ZPRO or not use the below logic
    MaterialNumber                                            Then(FG)
                          ------equalS(TextFunction) ---- not -----ifWithElse ------------------ Target
    Constant (ZPRO)                                                   Else(FC)
    Regards,
    Abhishek.

  • Not equal is not working

    hi
    i write code in co extension below if (!weight.equals(weight_perc)) is not working how ever if("Core Objective".equals(Coreobjective)) is working here weight & weight_perc both are integers and Core objectives are string.
    public void processFormRequest(OAPageContext pageContext, OAWebBean webBean)
    super.processFormRequest(pageContext, webBean);
    OAApplicationModule am = pageContext.getApplicationModule(webBean);
    OAViewObject vo =(OAViewObject)am.findViewObject("ObjectivesVO");
    if ("Apply".equals(pageContext.getParameter(EVENT_PARAM)))
    String person_id = (new Integer(pageContext.getEmployeeId())).toString();
    pageContext.writeDiagnostics(this,"person_id: "+person_id,OAFwkConstants.STATEMENT);
    String s1 = pageContext.getDecryptedParameter("pObjectiveId");
    pageContext.writeDiagnostics(this,"s1 "+s1,OAFwkConstants.STATEMENT);
    String weight_perc =pageContext.getParameter("Weighting");
    pageContext.writeDiagnostics(this,"weight_perc: "+weight_perc,OAFwkConstants.STATEMENT);
    String objective= pageContext.getParameter("ObjectiveName");
    pageContext.writeDiagnostics(this,"Objective_Name: "+objective,OAFwkConstants.STATEMENT);
    String Coreobjective = objective.substring(0,14);
    pageContext.writeDiagnostics(this,"Coreobjective: "+Coreobjective,OAFwkConstants.STATEMENT);
    String query="select weighting_percent from per_objectives where objective_id ='"+s1+"'";
    String weight = null;
    try
    pageContext.writeDiagnostics(this,"Enters into try block",OAFwkConstants.STATEMENT);
    PreparedStatement ps= am.getOADBTransaction().getJdbcConnection().prepareStatement(query);
    ResultSet rs=ps.executeQuery();
    pageContext.writeDiagnostics(this,"Excute the quiery",OAFwkConstants.STATEMENT);
    while(rs.next())
    weight =rs.getString(1);
    pageContext.writeDiagnostics(this,"weight: "+weight,OAFwkConstants.STATEMENT);
    catch(Exception e)
    e.printStackTrace();
    if("Core Objective".equals(Coreobjective))
    if (!weight.equals(weight_perc))
    pageContext.writeDiagnostics(this,"ENTERS INTO EQUAL CONDITION: ",OAFwkConstants.STATEMENT);
         MessageToken[] errTokens = { new MessageToken("VOLDWEIGHTAGE", weight)};
    throw new OAException("XX_PG", "XXBPTY_COREOBJ_WEIGHT_NOCHANGE", errTokens);
    plz help me.
    Regars,
    sharif.

    Before you do equals check, you should check if any of the value is null or not.
    Both the values are numbers, but you are getting them into strings. So you have to do string compare.
    Or it's easier to get them as numbers and use logical operators as suggested by other fellow experts to compare.
    If you still want to go for Strings here is what you need to do(may be bit cautions here)
    if ((str1!=null || !"".equals(str1))&& (str2!=null || !"".equals(str2)) && str1.equals(str2)){
    Yes both of them are same
    else{
    They are different.
    Regards,
    Peddi.

Maybe you are looking for

  • Questions about the Galaxy Tab on Verizon

    Hello Samsung is saying that the Galaxy Tab is comming to Verizonwireless soon. Rumors are sometime in November. I'm really excited about this product but I'm a little in the dark on some of the features and capabilties Verizonwireless will have for

  • Where can I download the instant client ODBC driver for windows 7

    I upgrade to windows 7 and my instant client connecting to oracle from ms Access stop working. Is there any documentation on how it works on windows 7. I use instant client and odbc cleint for xp. Thanks

  • BW upgrade from 3.5 to BI 7.0 before R/3 Upgrade

    What are the implications  if we upgrade our BW system first form BW: 3.5 (BCT 3.53) to BI7.0 then upgrade our R/3 :SAP 4.6C system to 2004s. R/3 upgrade will be done after BW upgrade Please advise

  • Plug in for Adobe X Pro   How to straighten Text Lines

    I know I've asked this question before, but I've seemed to have misplaced the answer. I have to scan a lot of over used documents. As most of you know the text starts curving after a paper gets copied too many times. I am looking for a plug in for ad

  • Public class name same as filename

    Every book I've read stated that if you have a public class declared in the source file, then you have to name the file the same as the class name. However, none of the book explain why, can anyone tell me about this?