Convert c# to Java code - Floating Point Arithmetic

Convert c# to Java code - Floating Point Arithmetic

Hello
I need to write a c# equivalent in java code. The c# code includes functions perform mathematical calculations. The result of these functions must match exactly with the c# (especially precision) counterpart. Here's a function that requires an equivalent java

Public Shared Function squareroot (string n1)
{
If ((n1 == null) |) (System.Convert.ToDouble (N1) < 0))
{return null ;}
else {}
return (Math.Sqrt (System.Convert.ToDouble (n1))) System.Convert.ToDecimal. ToString();
}
}

C# two data types - float (32-bit) and double (64-bit) floating-point. It also includes a more specific data type float called decimal (128-bit). The float and double are supposed to follow the standard IEEE 754 floating point standard, but precise figures are different. Double c# has 15-16 digits for precision while the equivalent of java has 53, right? (the IEEE standard reference).

Does anyone have an idea on what java equivalent data types/libraries must be used such that the results correspond with double c# and decimal?

Thank you & happy new year

This has nothing to do with the IEEE 754 standard, because nothing in IEEE 754 specifies how many decimal places should be used when a value is converted to a string. Simply because the resolution is between 15 and 16 decimal places does not mean that there is always an exact representation of any number of IEEE 754 format to 16 decimal places. In your example, Java chooses to create two decimal places more than c# don't but I bet that this is not a general rule you can count!

The whole concept of using strings to represent the number seems to be skewed. I don't really see the point. It is mind bogglingly slow and in my view it does nothing for you. You have not yet met the real problem yet! What happens when Java or c# decides to use scientific notation?

In your situation I would like to change the program c# use 'double' rather than 'chain', then you would find that you get an almost perfect match to all time. I make this recommendation of much written spending year of algorithms in C, C++, c# and Java of signal processing.

Tags: Java

Similar Questions

  • BUG: Large floating point numbers convert the wrong integer

    Hello

    When you use the 'balls' conversion to convert integers to SGL, DBL and EXT there are certain values that convert evil. An example is the 9223370937343148030 integer that can be represented exactly as a SGL (and therefore exactly as DBL and EXT as well). If you convert this I64 you get 9223370937343148032 instead, even if the correct integer is in the range of an I64. There are many cases similar, all (I noticed) at the wide end of the ranges.

    It has nothing to with the integers can be represented exactly as a floating point value or not. This is a bug of authentic conversion you mind.

    See you soon,.

    Steen

    Hi Steen,

    Thanks for this identification. I confirmed the EXT to U64 conversion problem in simply trying to make a round trip on a xFFFFFFFFFFFFF9B0 of value U64 EXT and back, is xFFFFFFFFFFFFFFFF as well (and the intermediate value in EXT is correct).

    The problem seems to be limited to integer values with the upper part of 53 bits set, as well as all of one or more of the 11 lowest.

    I have reported this (#396305), as well as the limited display accuracy questions (#396337).

    Jim

  • How to convert hex 8 bytes floating point double?

    Hello

    I want to know how to convert a string of 8 bytes of data double floating-point.

    data (HEX): 40 02 70 40 00 00 00 4F

    Thank you.

    DP

    This string of 8 bytes of data is actually a string? Are the characters in the string of letters or you have hex values? Ultimately you want to use the Type Cast:

  • floating point to hexadecimal string

    Hello

    Is attached a screenshot of what I'm trying to do.

    The equation that I in the formula box basically is supposed to enter a number between 30 and 100 (which represents the intensity percentage) and he will give a value in which when converted to the spell and fed in my instrument will give the corresponding intensity in floating-point (ie. 30% if I had entered 30 as my x in the formula) I need. Thus, for example my lowest intensity (30) would give me a decimal value of 239 of the formula which is "EF" in hexadecimal.

    This code does not work for some reason any. If I replace my conversion function of formula and hexadecimal, with only a simple chain control and display of spell and EF entry switch and feed it into the instrument intensity makes the adjustment to 30%! But I prefer to use the scale bar instead which does not... Can someone please tell me if my conversion function is messed up or something.

    Thank you!

    Try this.

  • floating point No. the chain with the same precision

    I use "format string" to convert floating point No. to a string. Most of the numbers have a single decimal digit, so I use '%^0.1f' in the format in the connection string. But for our whole. like 150, it gets converted to 150,0. I want to avoid this, such that the chain looks exactly like the No.... What should I change?

    Use %#0.1f as your format string.

    Read the help file on the format codes.  The sign # told him to truncate the zeros.

  • Query - error converting data type varchar to float.

    All pop up error message is

    java.sql.SQLException: [Macromedia] [SQLServer JDBC Driver] [SQL Server] error...

    I use CF10 Report Builder. Here's my query:

    SELECT name.first_name, name.last_name, name.soc_sec, name.name_le1, name.camp_cod, term AS LEFT(MMTemp.term_int, 6), MMTemp.st_addr, MMTemp.add_addr, MMTemp.city, MMTemp.state, MMTemp.zip, transact.sch_yr AS SchYr, transact.ref_id AS AwardDesc, transact.offered AS AwdAmt, nmact.act_memo, MMTemp.Operator, rpt_schy.token, nmbudget.nmbudget_tuition AS tuition, nmbudget_RM_BRD AS RoomBoard,

    CASE

    WHEN finaideurekaawdcat.finaidawdcat_cod like '% E' GOLD finaideurekaawdcat.finaidawdcat_cod as "OT" and THEN "Gift aid & schlorships.

    WHEN finaideurekaawdcat.finaidawdcat_cod = 'FG' THEN 'need based aid.

    WHEN finaideurekaawdcat.finaidawdcat_cod = "FL" AND "federal ready direct.

    ELSE 'work study' END as CatType

    / * CASE WHEN name.camp_cod = "AdultLearn" THEN '17911' ELSE '20510' END HAVE tuition.

    CASE WHEN name.name_le1 = 0 THEN '8835' ELSE '0' END AS RoomBoard * /.

    Name, MMTemp, nmact, transact, finaideurekaawd, finaideurekaawdcat, rpt_schy, nmbudget

    WHERE (MMTemp.Operator = rpt_schy.token or MMTemp.Operator = Right(MMTemp.Operator,8))

    AND MMTemp.soc_sec = name.soc_sec

    AND MMTemp.soc_sec = nmact.soc_sec

    AND MMTemp.activity_cod = nmact.activity_cod

    AND MMTemp.soc_sec = transact.soc_sec

    AND MMTemp.activity_cod = 'AM'

    AND MMTemp.soc_sec = nmbudget.soc_sec

    AND transact.tcodes = 'AW'

    AND transact.accept <>'v '.

    AND transact.sch_yr = rpt_schy.sch_yr

    AND rpt_schy.token = ' #session.token # '.

    AND transact.awd_id = finaideurekaawd.finaidawddesc_cod

    AND finaideurekaawd.finaidawdcat_cod = finaideurekaawdcat.finaidawdcat_cod

    UNION

    SELECT finaideurekaawddesc.finaideurekaawddesc AS AwardDesc, finaideurekaawd.finaideurekaawdtot AS AwdAmt, name.first_name, name.last_name, name.soc_sec, name.name_le1, name.camp_cod, LEFT (MMTemp.term_int, 6) AS a term, MMTemp.st_addr, MMTemp.add_addr, MMTemp.city, MMTemp.state, MMTemp.zip, MMTemp.activity_cod, MMTemp.Operator, finaideurekaawd. Sch_years AS SchYr, nmact.act_memo, nmbudget.nmbudget_tuition AS tuition, nmbudget_RM_BRD AS RoomBoard,

    CASE

    WHEN finaideurekaawdcat.finaidawdcat_cod like '% E' GOLD finaideurekaawdcat.finaidawdcat_cod as "OT" and THEN "Gift aid & schlorships.

    WHEN finaideurekaawdcat.finaidawdcat_cod = 'FG' THEN 'need based aid.

    WHEN finaideurekaawdcat.finaidawdcat_cod = "FL" AND "federal ready direct.

    ELSE 'work study' END as CatType

    / * CASE WHEN name.camp_cod = "AdultLearn" THEN '17911' ELSE '20510' END HAVE tuition.

    CASE WHEN name.name_le1 = 0 THEN '8835' ELSE '0' END AS RoomBoard * /.

    OF MMTemp, nmact, finaideurekaawd, finaideureka, finaideurekaawddesc, finaideurekaawdcat, rpt_schy, nmbudget

    WHERE (MMTemp.Operator = rpt_schy.token or MMTemp.Operator = Right(MMTemp.Operator,8))

    AND MMTemp.activity_cod = 'AM'

    AND MMTemp.activity_cod = nmact.activity_cod

    AND finaideurekaawd.sch_years = rpt_schy.sch_yr

    AND rpt_schy.token = ' #session.token # '.

    AND MMTemp.soc_sec = name.soc_sec

    AND MMTemp.soc_sec = nmbudget.soc_sec

    AND name.soc_sec = nmact.soc_sec

    AND name.soc_sec = finaideurekaawd.soc_sec

    AND name.soc_sec = finaideureka.soc_sec

    AND finaideurekaawd.finaidawddesc_cod = finaideurekaawddesc.finaidawddesc_cod

    AND finaideurekaawd.finaidawdcat_cod = finaideurekaawdcat.finaidawdcat_cod

    ORDER BY name.soc_sec

    I don't see anywhere that I convert varchar to float.

    Which data fields are defined as floating point?

  • Decimal in Floating point with cookers

    Hello

    I am wanting to convert a decimal value to be implemented at the scale of a floating point value.

    For example.

    a decimal value from 0 to 20000 where half is considered to be the zero point. Then share values and on the other of this average value are considered postivie or double negative (0-10000 considered negative, 10001 to 20000 considered as positive). Then, the resolution of each decimal value is compared to a predefined scale.

    Don't know how to do in this regard.

    Any help is much appreciated.

    Hello

    I hope I got everything you wanted.

    Please take a look at the attachment.

    Paulie

  • How to create programably InputComoboxListOfValues in java code

    12.1.3 jdev

    I'm trying to dynamically create InputComoboxListOfValues in the java code as follows.

    RiLOV RichInputComboboxListOfValues = new RichInputComboboxListOfValues();
    riLOV.setLabel (label);
    riLOV.setId ("iclov" + ind);
    riLOV.setVisible (true);
    riLOV.setRendered (true);
    riLOV.setSimple (true);
    riLOV.setContentStyle("text-transform:uppercase;");
    riLOV.setValue (defaultValue);
    riLOV.setPopupTitle ("search dialog box");
    riLOV.setAutoSubmit (true);

    I also need to

    riLOV.addLaunchPopupListener (myLaunchPopupListener);

    riLOV.addReturnPopupListener (myReturnPopupListener);

    My question is how to build myLaunchPopupListener /myReturnPopupListener

    Thank you.

    riLOV.addLaunchPopupListener (myLaunchPopupListener);

    riLOV.addReturnPopupListener (myReturnPopupListener);

    Instead of addX() methods, you can use the setX() methods that use the MethodExpression as parameter.

    Example for MethodExpression: Blog in Java Evangelist John Yeary: JSF 2.x tip of the day: creation by programming MethodExpression EL

    But, af:inputListOfValues / af:inputComboboxListOfValues components require a very complex model to activate filtering etc so this can be very difficult to implement correctly if they are not supported by the link layer.

    From here you can download components done face ADF demo and see how this can be implemented: Application Development Framework downloads

    BTW,

    riLOV.setContentStyle("text-transform:uppercase;");

    Of course, you know that this only display value in uppercase on your page and does not convert the value in the data model?

    Dario

  • 11g R1 spot java code create an adapter IOM is not updated.

    I am trying to create a task of the adapter and I'm having a problem with the java code. I tried both adding the jar in the javatasks folder using download/remove the jars and utility I always encounter the same problem. The question I have is that even if I add that a pot back into the folder javatasks the task of the adapter refers to the former classes that were used, which causes various as errors method not found. Are the steps I took, delete the javatasks file jar, remove the adapter, purge the cache, restart the server and then turn the jar java tasks and redo the adapter. I also tried all the previous steps using download jars and rename the jar and try again. None appeared to update the java code. I wonder also why this thread was deleted, because his problem seemed similar to mine. https://forums.Oracle.com/forums/thread.jspa?MessageID=10682516 & tstart = 0

    I tried all the steps in this thread here is the google cache, so you can watch it thanks.

    http://WEBCACHE.googleusercontent.com/search?q=cache:https%3A%2f%2Fforums.Oracle.com%2Fforums%2Fthread.jspa%3FmessageID%3D10682516%26tstart%3d0 & ei = xxKdUKiaI5Lo8wS3yoDYBA & usg = AFQjCNEdUCQ9prsxw6pp7RumPPm3VMHHHQ

    Finally, the server is in production mode so I know that a reboot may be necessary, however, I have not had problems in the past with the update of the maps on the same server and did not need to restart downloading at the request of the task or event handlers.

    Published by: 970312 on November 9, 2012 08:04

    Have you checked OIMHOME_JAR table?

    Run PurgeCache.sh All
    Restart the server
    Also try to remove the content of point of mounting/tmp directory

  • Where to put the java code - best practices

    Hello. I work with the Jdeveloper 11.2.2. I'm trying to understand the best practices for where to put the code. After reviewing the http://docs.oracle.com/cd/E26098_01/web.1112/e16182.pdf, it seemed that request module was the preferred location (although many examples in the pdf file reside in the main methods). After some time of coding, if, I noticed that there was a certain libraries imported and wondered if this would impact performance.

    I looked at the articles published on the forum, in particular Re: programmatically access the method of service (customer interface) . This link mentions for access to the code a bean of support - and the bulk of the recommendations seem to be using the data control to drag to the Joint Strike Fighter, or use the links to access code.

    My interest lies in where to put the java code in the first place; In the view object, entity object, and... other Am, backing bean object?

    I can describe several guess better know where to put the code and the advantages and disadvantages:

    1. in the application module
    Benefits: Central location for code makes development and support easier as there are not multiple access points. Kinda like a data control centralizes the services, the module of the application can act as a conduit for the different parts of the code you have in your model objects.
    Cons: Everything in one place means that the module of the application becomes bloated. I don't know how the memory works in java - if the app module has tons of different libraries are all called when even a method of re - run a simple query is called? Memory of pigs?

    2. write the code in the objects it affects. If you write code that accesses a view object, write it to a display object. Then make it visible for the customer.
    benefits: the code is accessible through ducts less (for example, I expect that if you call the module from the application of a JSF backing bean, then the module of the application calls the view object, you have three different pieces of code-)
    CONT: the code gets spread, more difficult to locate etc.

    I would greatly appreciate your thought on the issue.


    Kind regards
    Stuart

    Published by: Stuart Fleming on May 20, 2012 05:25

    Published by: Stuart Fleming on May 20, 2012 05:27

    First point here is when you say 'where to put the code of java' and you're referring to ADF BC, the point is that you put 'code of java business logic' in the ADF business components. Of course it is very good to have the Java code in the ViewController layer that covers the user interface layer. Just don't put the business logic in the user interface layer and don't put no logical user interface in the model layer. In your 2 examples you seem to consider the ADF BC layer only, so I'll assume that you're not only serious logic java code.

    Meanwhile, I'm not keen on best practices in the term that people are following best practices without thinking, usually best practices come with conditions and forget to apply. Fortunately you do not here that you have thought through the pros and cons of each (nice work).

    Anyway, back on topic and turn off my soap box, regarding where to put your code, my thoughts:

    (1) If you have only 1 or 2 methods set in the AppModuleImpl

    (2) If you have hundreds of methods, or there is that a chance #1 above will turn into #2, divide the code between the AppModuleImpl, the ViewImpl and the ViewRowImpls. Why? Because your AM will become overloaded with hundreds of methods making it unreadable. Put the code where it should logically go instead. Methods that operate on a specific line of VO Approfondissez partner ViewRowImpl, methods that work across lines in a VO enter the ViewImpl and methods that work throughout your in the associated AppModuleImpl.

    To be honest that you never the option you choose, one thing I recommend as a best practice is to be consistent and document standard so not know your other programmers.

    BTW, it is not a question about loading a lot of libraries/imports in a class, it has no performance cost. However if your methods require a lot of class variables, then yes there will be a memory of the costs.

    On a side note, if you are interested in more ideas on how to create ADF applications properly think about joining the EMG "ADF", a forum which deals with ADF architecture, best practices (cough), deployment architectures free online and more.

    Kind regards

    CM.

  • How to create a BPEL Process task using java code

    Hello

    I created a BPEL process (for creating task), in which my requirement is that I need to create a task based on some inputs and assign it to the user in partucular and then get out of this flow.

    earlier, I felt that I will use the human task activity. but when I use that task will be created in the same process and proceedings will be stuck on there until human intervention (the BPEL process waits for the result.).

    is it possible that I can use Java activity and create tasks from java code, 'I know how to assign a specific user task. Please tell me.
    Abhishek

    Published by: abhishek on April 25, 2011 12:42 AM

    Hi Abhishek
    1. you can try this alternative approach and it should work.

    2. basically, most of the BPEL process eventually auto generated Web services (.) WSDL). When we create a BPEL process, everything we do is give diagram of input, output schema and creates a bpel process with the default operation named as "process" in all the old versions as up to 11.2 SOA (and maybe before). BUT SOA 11.3 from, we can create a process BPEL, with our own WSDL and our own scheme. There is no restrictions like having only a single operation named 'process', etc.. In any case, what I mean is, each BPEL process ends up as a WebService, with entry and exit of the payloads of XSD.

    3. from the JDeveloper itself, locate the .wsdl for your BPEL process under the Workflow project. Create a new project of Proxy customer service Web and generate a customer for this wsdl Web service proxy. This will create you Service, Port and JAVA classes equivalent payload theoretically in your case taskpayload.xsd with these 4 items you have. Ignore the full blown the HumanTask which has all the system elements and attributes of a task of bpel. All you need is to undertake a task with your own payload data. Create a simple Client Java (EJB or Servlet later to make more flexible). In this Java client, retrieve the Service object in the proxy and port. Then instantiate the java class that represents the payload. Set 4 values you want and set the user name, etc. You may need some adjustments for the setting of the user. Then the port invoke otherwise (go your java object here).

    Sample code snippet
    prepare the message for BPEL of appeal; Define the fields that can not be null
    MyPayloadRequest myPayloadRequest = new MyPayloadRequest();
    myPayloadRequest.setInitiator("");
    myPayloadRequest.setTitle("");
    myPayloadRequest.setEmployeeName("");
    myPayloadRequest.setEmpContact("");

    web service client Get for BPEL receive point and call: first generate client proxy
    MyBPELPProcess_client_ep serviceClient = new MyBPELPProcess_client_ep();
    MyBPELPProces proxy = serviceClient.getNewMyBPELPProces_port ();
    proxy. Process (myPayloadRequest);

    Please note that you can also use the SOA workflow API and the Manager back call personalized for this first task classes. In this class, you can have the methods of the interceptor, which is called each time a task is initiated, saved, Submit, approve etc etc (all events essentially). This gives you access to all the objects in a workflow with full charge blown. So you can always get the data you pass above and in this custom class, the value of the user, date/time etc..

    It's just a different approach you can try.

    Thank you
    Ravi Jegga

  • Example of Java code to publish in Flex?

    I have Tomcat talking to Flex with BlazeDS, but the conversation is one of the ways.  Flex has to initialize it.

    I want to be able to publish to Flex from Java (in Tomcat).  There are fine examples of the code necessary to capture Flex and how to subscribe and everything, but I can't find excerpts from Java that show how we launch this conversation on this end.

    Can someone point me to some examples of code for this?

    Thank you!

    Hello

    Should have the URL: http://help.adobe.com/en_US/dataservicesjee/4.6/Developing/WS9d22440892c78ffa-3a437432122a 8558cdf - 8000Update.html

    Regarding the subscription of java, see how the consumer subscribe comes Flex (the source code for the consumer class is viewable in FB). You need to basically imitate in your java code. This means roughly the following manner:

    1 authenticate your self and make sure that this main user gets put on the FlexContext.

    2. create a command message to the subscription (with values that are appropriate as client id, etc.) and go to the MessageBroker.routeCommandToService (subscriptionCmd, null).

    Rohit

  • The use of java code in apex?

    Hello

    I have a code in Java and I want to use in the apex. Can you show which is the best way to do it?

    Thank you very much.

    Normally load you the java in the database and run it from there... What exactly does the java code you don't?

    Thank you

    Tony Miller
    Webster, TX

    Never give up dreams!
    JMS

    If you answer this question, please mark the thread as closed and give points where won...

  • Qosmio F50 - Webcam Error - Invalid floating point operation

    Hello

    I have a Qosmio F50 (4 weeks) problem is after two weeks webcam stopped working * not valid floating point operation *.
    I have to close the program via the Task Manager, * software camera Wizard does not *.

    Have you tried next.
    Update all drivers, System Restore

    Toshiba help line after all the efforts suggest all reinstall them it is aggressive for me, because he would lose some software on the laptop that I had to transfer old PCs and had to plead with some software companies to transfer (as a single license etc.).

    If someone else has had this problem and is there a simple solution

    Will be

    Hmm, you could remove the software of the webcam of the system and could remove too the webcam from the Device Manager.
    Then you could clean the operating system using the CCLeaner

    This software is free and it can clean the registry and the system. I use it very often.
    Then restart the laptop and try to reinstall the software of webcam again.

    Good luck

  • Determine if an integer is a floating-point number

    I want to create a program that when an integer is entered in the digital constant, a floating-point number with zeros to the right of the decimal point lights up the LED on the front panel. The LED remains off for any other floating-point number. I know I want to use a ride to the nearest function, but don't know where to go from there.

    rtufaro wrote:

    I want to create a program that, when an integer is entered in the digital constant,.

    You want to say CONTROL, right?

    You just need a type of rounding.  No matter if round you upwards or downwards.  If you just around and then compare the entry to the rounded value.  If they are equal, you turn on your LED.  So all you need is a digital control, 2 functions, and a boolean flag.

Maybe you are looking for