Arbitrary? Number Modification

A little background info: I'm trying to program an understanding of units of time, and be able to convert milliseconds to seconds to minutes to all the rest and back again.
The code below successfully converts the current time from milliseconds to seconds to milliseconds (most of the time) and prints the value after each step. My problem is that it sometimes adds a little bit to the end, and an example of the malformed output then one of the expected output are at the end of this post.
package jesdisciple.util.units;
public final class Type {
    public static final Type TIME = new Type();
package jesdisciple.util;
public final class JesAmount {
    private final JesUnit u;
    private final double v;
    public JesAmount(double value, JesUnit unit) {
        v = value;
        u = unit;
    public final boolean equals(JesAmount amount){
        return v == amount.v && u.equals(amount.u);
    public final JesAmount convertTo(JesUnit unit){
        if(!unit.type.equals(u.type)) throw new IllegalArgumentException("Cannot convert to a dissimilar unit type.");
        return new JesAmount(v * (u.factor / unit.factor), unit);
package jesdisciple.util;
import jesdisciple.util.units.*;
public final class JesUnit {
    public static final int MAXIMUM_PRECISION = 3; // I'm unsure what this value should be.
    public static final JesUnit SECOND = new JesUnit(Type.TIME, " s", -1);
     * Identifies what type of quantity this unit measures.
    public final Type type;
     * Describes what {@link JesAmount#toString() JesAmount.toString()} should append to the value,
     * such as " m" (for meters) or "$" (for dollars).
    public final String notation;
     * Describes how many digits after the decimal point should be retained.
    public final int precision;
     * Describes the numeric relation between the {@link #bases base unit(s)}
     * and this unit. (I.e., 12 is the factor of a foot to an inch, 1000 is
     * the factor of a kilometer to a meter, and 0.001 is the factor of a gram
     * to a kilogram.)
    public final double factor;
     * Describes where to put the notation. The default value is {@code true},
     * which renders the notation after the value, so {@code true} need not be
     * specified in any constructor. {@code false}, on the other hand, must be
     * specified.
    public final boolean after;
     * Holds representation(s) for the one or two units from which this is
     * derived.
    public final JesUnit[] bases = new JesUnit[2];
    private JesUnit(Type t, String notation, int precision, boolean after){
        this.type = t;
        this.factor = 1;
        this.notation = notation;
        this.precision = precision == -1 ? MAXIMUM_PRECISION : precision;
        this.after = after;
    private JesUnit(Type t, String notation, int precision){
        this(t, notation, precision, true);
    public JesUnit(JesUnit u, double factor, String notation, int precision, boolean after){
        this.type = u.type;
        this.notation = notation;
        this.precision = precision == -1 ? MAXIMUM_PRECISION : precision;
        this.bases[0] = u.getBase();
        this.factor = factor * (u.isBase() ? 1 : u.factor);
        this.after = after;
    public JesUnit(JesUnit u, double factor, String notation, int precision){
        this(u, factor, notation, precision, true);
    public final JesUnit getBase(){
        if(bases[0] == null){
            if(bases[1] == null) return this;
            else return bases[1].getBase();
        }else{
            if(bases[1] == null) return bases[0].getBase();
            else return this;
    public final boolean isBase(){
        return (bases[0] == null) == (bases[1] == null);
package jesdisciple.lang;
import jesdisciple.util.*;
public class JesMain {
    public static void main(String[] args) {
        JesUnit millisecond = new JesUnit(JesUnit.SECOND, 0.001, " ms", 0);
        JesAmount timeMillis = new JesAmount(System.currentTimeMillis(), millisecond);
System.out.println(timeMillis);
        JesAmount time = timeMillis.convertTo(JesUnit.SECOND);
System.out.println(time);
        timeMillis = time.convertTo(millisecond);
System.out.println(timeMillis);
init:
deps-jar:
compile:
run:
1.183856340906E12 ms
1.1838563409060001E9 s
1.1838563409060002E12 ms
BUILD SUCCESSFUL (total time: 0 seconds)Here is the expected and usual output:init:
deps-jar:
compile:
run:
1.183856340906E12 ms
1.183856340906E9 s
1.183856340906E12 ms
BUILD SUCCESSFUL (total time: 0 seconds)Can this be fixed somehow, or is it a bug in Java itself?

How do you suggest that I fix it? According to http://java.sun.com/developer/JDCTechTips/2003/tt0204.html#2,
There are several ways to fix the equality testing problem illustrated above. You could check that d and val2 are close in value rather than exactly equal. Or you could use the BigDecimal class, and opt out of floating-point arithmetic entirely.
Ironically, I tried BigDecimal earlier and got stranger numbers than shown above. JesAmount should have this method:    public final String toString(){
        String out = u.notation;
        out = u.after ? v + out : out + v;
        return out;
    }, but I deleted it as irrelevant earlier, and this algorithm instead of the other:    public final JesAmount convertTo(JesUnit unit){
        if(!unit.type.equals(u.type)) throw new IllegalArgumentException("Cannot convert to a dissimilar unit type.");
        return new JesAmount(v.multiply(new BigDecimal(u.factor).divide(new BigDecimal(unit.factor))), unit);
    }, and this constructor:    public JesAmount(BigDecimal value, JesUnit unit) {
        v = value;
        u = unit;
    }, and JesMain should have this one:    public static void main(String[] args) {
        JesUnit millisecond = new JesUnit(JesUnit.SECOND, 0.001, " ms", 0);
        JesAmount timeMillis = new JesAmount(new BigDecimal(System.currentTimeMillis()), millisecond);
System.out.println(timeMillis);
        JesAmount time = timeMillis.convertTo(JesUnit.SECOND);
System.out.println(time);
        timeMillis = time.convertTo(millisecond);
System.out.println(timeMillis);
    }, both classes now importing java.math.*. Here is the output from that:init:
deps-jar:
Compiling 1 source file to C:\Program Files\netbeans-5.5.1\projects\Jesdisciple\build\classes
compile:
run:
1183897140296 ms
1183897140.296000024644809948959345291541467304341495037078857421875000 s
Exception in thread "main" java.lang.ArithmeticException: Non-terminating decimal expansion; no exact representable decimal result.
        at java.math.BigDecimal.divide(BigDecimal.java:1514)
        at jesdisciple.util.JesAmount.convertTo(JesAmount.java:49)
        at jesdisciple.lang.JesMain.main(JesMain.java:33)
Java Result: 1
BUILD SUCCESSFUL (total time: 5 seconds)Message was edited by:
Jesdisciple

Similar Messages

  • How do I fix the format of plot lines for an arbitrary number of sets of data plotted on the same x-y graph?

    I have written a VI to control an LCR meter and perform sweep functions. I have two x-y graphs on my front panel (one for each of 2 measured parameters). The VI is designed with a button to take a measurement, plot the data, and then wait for another event (like write data, clear plot, or measure again). The user can take simultaneous measurements and these are plotted on top of the data already there in the same x-y graphs (using an array of clusters with shift registers). There is no limit on how many sets of data can be on the x-y graph. 
    Now, my issue is in formatting the plot lines (color, thickness, marker type). I can fix the first plot line by adjusting the parameters of the x-y graph. However, I also want to control the format of all consecutive plot lines. How can I do this for an arbitrary number of lines? The main thing I want to do is to have all of them show the square marker type (the default is no marker type, just a line). 
    Thanks!

    Hi maximum23,
    You can use properties of plot to format the plot lines. You just have to select Active plot using property and then select color and line width etc..
    You can define color and width etc parameter by asking user or you can just make them default.
    Gaurav k
    CLD Certified !!!!!
    Do not forget to Mark solution and to give Kudo if problem is solved.

  • [ETL]How to transform a Source model into an arbitrary number of target models ?

    Hi all,
    I need to know how to transform a source model into an arbitrary number of target models which conforms to different target metamodels using ETL ? Is there any examples that can help me ?
    Thank you
    Mana

    Hi Antonio,
    Actully I mean the number of metamodels are known.For example, assume that there are two known metamodels in the target side, the first one is the target metamodel, and the second one is the trace metamodel .
    I would like to see an example of ETL transformation that run on a source model and generate the target model and the trace model as well. This statement is part of the chapter 5 of the ebook which says "it is often essential to be able to access/update additional models during a transformation (such as trace or configuration models). Building on the facilities provided by EMC and EOL, ETL enables specification of transformations that can transform an arbitrary number of source models into an arbitrary number of target models."
    could you please explain this more for me or provide me with an example.
    Thank you
    Mana

  • Arbitrary Number Generated before Sales Order Document number is Generated

    I want to know which is the arbitrary number generated before the sales Order Document number is created. In which table the arbitrary number is stored?
    The Exit which triggers the arbitrary number in the transaction VA01?

    Hi
    You get the Arbitrary number throug the FM NUMBER_GET_NEXT.
    interne Nummernvergabe
            data: da_rc like inri-returncode.
            call function 'NUMBER_GET_NEXT'
              exporting
                nr_range_nr = da_numki
                object      = 'RV_BELEG'
              importing
                returncode  = da_rc
                number      = vbak-vbeln.
    And regarding userexit, there is
    perform userexit_number_range using da_numki statement in include MV45AF0B_BELEG_SICHERN.
    Regards
    Raj

  • Tiling a rectangle with arbitrary number of rectangles

    I'm trying to figure out how to tile a rectangle (the stage) with an arbitrary number of rectangles. Simple tiling where all the tiles are the same size and simply stacked in a grid.
    I'm doing this with a resizable layout and a number of tiles that is arbitrary and will change over time.
    Given a more or less 4:3 or 16:9 monitor I would like a solution that tends toward minimizing the perimeter of the tile and being similar in aspect ratio to the screen. I realize that if I have a prime number of tiles that I won't be able to make a nice grid, but other than that it seems there should be some way to do this.
    Lets say I have 231 tiles I need to arrange. The factors are 1, 3, 7, 11, 21, 33, 77 and 231.
    If the screen is really, really wide 1 x 231. Wide but not not as crazy wide as before 3 x 77. And most likely 11 x 21 is what I would need.
    So is there an easy way to do this on the fly? Is there a pre-calculated way to make it easy?

    I've found some algorithms for doing a prime factorization of a given number, but not one for finding all the factors. Anybody got a suggestion?

  • Arbitrary number of parameters

    I try to call a method defined to accept an arbitrary number of parameters, in particular in the following piece of code:
    String catalogPath = "/path/to/catalog";
    Constructor constr = resolverClass.getConstructor(
      new Class[] {CatalogManager.class});
    Object obj = constr.newInstance(catalogPath);where the method newInstance (see java.lang.reflect.Constructor) is declared as follows:
    public T newInstance(Object... initargs)
                  throws InstantiationException,
                         IllegalAccessException,
                         IllegalArgumentException,
                         InvocationTargetExceptionHowever, this piece of code is rejected (method not applicable to String). Casting the String into an Object returns the same comment, now for Object. Putting the String into an array and passing that array as a parameter is compiled without any problems but then throws an IllegalArgumentException with the message "type mismatch".
    What am I doing wrong here? Or is that in fact a compiling problem? (I'm using Java SE 1.6.0_01).
    Dieter

    Dear endasil,
    many thanks for your helpful comments! In fact, I was slightly confused about my own writing after reading your comment!-)
    What I really wanted to do was the following:
    CatalogManager mgr = new CatalogManager(path);
    CatalogResolver res = new CatalogResolver(mgr);In the meantime, I have found a way to avoid Reflection so the problem has gone for the moment. But I tried to rewrite the snippet above correctly, and - at least - there are no compiling problems any more:
          String catalogPath = "/Dieter/JAVA_Beispiele/XSLT/build";
          CatalogManager cm = new CatalogManager(catalogPath);
          // get a CatalogResolver instance and preset its CatalogManager
          Class resolverClass = loader.loadClass(className);
          Constructor constr = resolverClass.getConstructor(
             new Class[] {CatalogManager.class});
          Object[] args = new Object[] {cm};
          Object obj = constr.newInstance(args);However, I have to explicitly use an array; just putting cm as a single argument instead of args is not accepted by the compiler!
    Many thanks for your (eye opening!) help!
    profos

  • Can ADF Faces tree components do an arbitrary number of levels?

    In the help/ADF Developers Guide for the latest version (JDev 10.1.3 build 3673), the section titled "Working with Master-Detail Relationships" shows an example of using the Tree Binding Editor to wire up an ADF Tree component. The process of doing "Add New Rule" to wire up each node of the tree suggests that the number of levels in the tree must be known beforehand.
    Is there any way to do the binding for an arbitrary number of levels (e.g. if you are using a composite pattern)?
    I'm guessing that if I can't do an arbitrary number of levels, I'll somehow be able to set up a maximum number of levels and have the component behave properly when less than the maximum are actually in use.
    TIA,
    Clark

    anyone?

  • Create output gui with arbitrary number of alv

    Hey guys,
    I am looking for a way to create a output gui (dynpro) with an arbitrary numbee of alc grids. The grids has different structures. Any ideas? I dont know the number of grids which shoild be displayed.
    If i use command write, thats quite easy but with alv is diffixult.
    Thy
      M.

    Hi
    This is just a little sample, all I hope is it can give you the beginning, just an idea to start to find a solution:
    TYPES: BEGIN OF TY_GUI,
             GRID      TYPE REF TO CL_GUI_ALV_GRID,
             CONTAINER TYPE REF TO CL_GUI_CONTAINER,
           END   OF TY_GUI.
    PARAMETERS: P_NALV TYPE I.
    DATA MAIN_CONTAINER TYPE REF TO CL_GUI_CUSTOM_CONTAINER.
    DATA SPLITTER       TYPE REF TO CL_GUI_SPLITTER_CONTAINER.
    DATA: T_GUI         TYPE STANDARD TABLE OF TY_GUI,
          W_GUI         TYPE TY_GUI.
    DATA: N_ROWS        TYPE I,
          N_COLS        TYPE I.
    DATA: L_ROW        TYPE I,
          L_COL        TYPE I.
    DATA: T_SFLIGHT    TYPE STANDARD TABLE OF SFLIGHT.
    START-OF-SELECTION.
      SELECT * UP TO 10 ROWS INTO TABLE T_SFLIGHT
        FROM SFLIGHT.
      CALL SCREEN 100.
    *&      Module  PBO  OUTPUT
    *       text
    MODULE PBO OUTPUT.
      IF MAIN_CONTAINER IS INITIAL.
        CREATE OBJECT MAIN_CONTAINER
          EXPORTING
            CONTAINER_NAME = 'MY_CONTAINER'.
        IF P_NALV = 1.
          CREATE OBJECT W_GUI-GRID
            EXPORTING
              I_PARENT = MAIN_CONTAINER.
          CALL METHOD W_GUI-GRID->SET_TABLE_FOR_FIRST_DISPLAY
            EXPORTING
              I_STRUCTURE_NAME = 'SFLIGHT'
            CHANGING
              IT_OUTTAB        = T_SFLIGHT.
        ELSE.
          N_ROWS = 2.
          N_COLS = CEIL( P_NALV / 2 ).
          CREATE OBJECT SPLITTER
            EXPORTING
              PARENT  = MAIN_CONTAINER
              ROWS    = N_ROWS
              COLUMNS = N_COLS.
          DO N_ROWS TIMES.
            L_ROW = SY-INDEX.
            DO N_COLS TIMES.
              L_COL = SY-INDEX.
              CALL METHOD SPLITTER->GET_CONTAINER
                EXPORTING
                  ROW       = L_ROW
                  COLUMN    = L_COL
                RECEIVING
                  CONTAINER = W_GUI-CONTAINER.
              CREATE OBJECT W_GUI-GRID
                EXPORTING
                  I_PARENT = W_GUI-CONTAINER.
              CALL METHOD W_GUI-GRID->SET_TABLE_FOR_FIRST_DISPLAY
                EXPORTING
                  I_STRUCTURE_NAME = 'SFLIGHT'
                CHANGING
                  IT_OUTTAB        = T_SFLIGHT.
              APPEND W_GUI TO T_GUI.
            ENDDO.
          ENDDO.
        ENDIF.
      ENDIF.
    ENDMODULE.                 " PBO  OUTPUT
    Max

  • Create a number of sub reports or table rows based on an arbitrary number

    I should note that I am using reporting services in SharePoint server mode and I am connecting to Sharepoint list data as my data source.
    In my SharePoint list item, it will have a property called quantity with a value of 5 for example.  In this case, I would want to create 5 subreports in my report (or a table with 5 rows).  Currently, I do not see how to accomplish this using Report
    Builder.  The table will only display a number of rows equal to the number of items returned from a dataset, which in this case would be 1.
    Is this possible to do?

    Katherin earlier said "In your scenario, you can insert 4 rows in the table, then insert values". 
    How do you do that?  That's the piece I don't understand.
    sqlstudy, below I have included more background on the requirements and details of what we are trying to do.  Here is another example of the dataset:
    Name____
    Description____
    Quantity
    Item1
    Tennis Balls
    2
    Item2
    Footballs
    3
    The requirement is that we need to print 5 pieces of paper that each have the item's name and description as well as an x of y sequence based on the quantity.  So the first piece of paper that prints out would say (Item1,Tennis Balls, 1 of 2), the second
    piece of paper would say (Item1,Tennis Balls, 2 of 2), the third piece of paper would say (Item2,Footballs, 1 of 3), the fourth piece of paper would say (Item2,Footballs, 2 of 3), and the fifth piece of paper would say (Item2,Footballs, 3 of 3).
    We are creating a system where users can print labels to identify boxes on pallets.  Each pallet can contain multiple boxes and the users need to label and identify each box.  The x of y sequence helps them keep the boxes together so things don't
    get mixed up.  The users deal with a lot of orders at once and would like to be able to print everything at once.  So, given the dataset above, they would check both item1 and item2, press print and expect to get the 5 pages as I described earlier.

  • Sync arbitrary number of episodes of podcasts (not 1, 3, 5, 10 or all)

    Hi - I'd like to synchronize a user-defined number of episodes of podcasts with my iPod and not be restricted to 1, 3, 5 10 or all (whatever is the sync logic). This is strange that this is not just a parameter for users to decide. Did I miss something ?
    Thanks

    Thanks but that does not solve my problem. I have 20 different podcasts feeds and each of them produces one episode a day (or every couple of days) and I want to have all the time the latest 30 (e.g.) episodes of all podcasts by just plugging my iPod and letting it getting sync'd. What you suggest would require manual selection every day and this is what I'm trying to avoid

  • Serial Number modification in Repair Order

    Hi,
    In a Sales / Repair Order (VA01), I have assigned a Serial Number via Extras --> Technical Objects for a Sub Item. I had then created a Delivery (VL01N) and Post Goods Receipt.
    If I open the Repair Order in change mode (VA02), I am able to modify the Serial Number despite completing Delivery and PGR.
    Likewise, I am able to modify the Serial Number in the Delivery different from the one specified in the Repair Order.
    Is there any config setting which can prevent this ?
    Thanks.
    Raj

    Hiii
    Please check it with the help of field selection for service/repair order. Else you have to take help from ABAP person to generate exxor message to prevent the same using USER_EXIST at the time of repair order saving.
    Regards
    Makarand Gurjar

  • CUP 7, CUPC7, Number Expansion, and AD number modification

    Does anyone have any experience of using the Number Expansion configuration option within CUP7. There is very little documentation on this.
    My hope was that you can use this to expand the number returned from AD following a CUPC client search before sending it to CallManager to be dialled.
    In my case the AD is populated with standard UK STD numbers starting with 0 (for example 01908123456. My CallManager Dial plan expects STD numbers to be prefixed with 9 (and a number starting with 0 will be routed to the switchboard).
    I created a specific number expansion in CUP 7 i.e. input number =01908123456, output number=901908123456. However it does not appear to work and the CUPC client reports 'bad number'.
    Has anyone used this feature in CUP 7 and can offer advise on how the feature should be used, or if there is anyway to modify the numbered returned from AD.

    You should use CUCM > Call Routing > Dial Rules > Application Dial Rules.
    Number Expansion on CUP is not designed for this purpose. It takes a while a explain, but it was designed to cater very, very rare situations. You should never use that.

  • Database Table where modifications to message long text are stored (log)

    Hi,
    As per manual correction mentioned in SAP note 1144291,
    we have changed the long text for message XC092 by modification of the long text.
    This note 1144291 is a pre-requisite for SAP Note 1310808.
    After the notes were implemented, it is noticed that message CURTO1055 has incorrect information in its long text. This is because, the variable in the long text are not correctly defined in the long text.
    Both the messages XC-092 and CURTO1-055 are SAP standard.
    The error for CURTO1-055 can be rectified by modification of the long text and maintenance of the correct variables.
    However, my question is:
    Where do we check the log for document modifcation for a message long text.
    I have found the logs relevant to my modification in table DOKHL and DOKIL.
    But in which table do we get all of the foll. data:
    - Message class
    - Message number
    - Modification name
    - Modification created by
    - Modification done on
    - Last changed by
    - Last changed on
    Kindly help. A <removed by moderator> solution would be really helpful.
    Best Regards,
    Smruthi
    Edited by: Thomas Zloch on May 5, 2011 12:07 PM - urgency reduced

    Hi Smruthi,
    The modification changes would be in the SMODILOG table. Please note this is a core basis table and should not be changed, however to best find your changes search under the TRKORR field with the relevant tp request.
    Best regards,
    Derrick Hurley
    Development Workench

  • Edit in External Editor only accepts a limited number of photos

    I occasionally want to edit a number of photos from my iPhoto library in an external editor (Photoshop). I have properly configured (as far as I know) the "Edit in external editor" setting, and it works correctly when I select a single photo. When I batch select multiple photos, the results vary: regardless of how many photos I select, Photoshop will only open somewhere between 1 and 4 of them. It seems to do better with shift+click to select rather than cmd+click, but in no case will it open more than 4 photos. Much of the time it will only open 2 photos, even if I have selected 7 or 8.
    Is there a way to open an arbitrary number of photos in an external editor?
    I'm using iPhoto 7.1.5 on OS 10.5.8. The external editor is Photoshop CS3.

    No there isn't. You can't send more than four at a time I'm afraid.
    Regards
    TD

  • Create array of arbitrary dimensions / get Class object for primitive types

    Here's an interesting problem: is there any way to code for the creation of an n-dimensional array where n is only known at runtime (input by user, etc.)?
    java.lang.reflect.Array has a newInstance method which returns an array of an arbitrary number of dimensions specified by the int[] argument, which would give me what I want. However, the other argument is a Class object representing the component type of the array. If you want to use this method to get an array of a primitive type, is it possible to get a Class object representing a primitive type?

    That doesn't help, since the whole problem is that the number of dimensions aren't known until runtime. You can't simply declare a variable of type int[][] or use an int[][] cast, since the number of []'s is variable.
    The int.class construction was partly what I was looking for. This returns the array needed (assuming some read method):
    int dimensions = read();
    int size = read();
    int[] index = new int[dimensions];
    for (int i = 0; i < dimensions; i++)
        index[i] = size;
    Object myArray = Array.newInstance(int.class, index);The only problem is, as an Object, I can't use myArray usefully as an array. And I can't use a cast, since that requires a fixed number of dimensions.

Maybe you are looking for

  • 8330 Video capturing issues

    Hi, I got a 8330 yesterday and I am having issues recording a video. After a master reset, the capturing works fine. As soon as I change the encryption mode under 'options/media card', the phone does not let me capture videos anymore, even after I ch

  • Problem during installation

    Hi, I'm installing EPSP9 (NW04 SR1) on Windows 2000Server/Oracle9206. I've successfully installed J2EE engine, but during portal installation at step "Check Portal Deployment Status" it gives error. Following errors reported in file j2ee\cluster\serv

  • Manage three different Levels of iOS?

    Well, I now have three devices, all maxed out at different levels of iOS.  Old iPad is two updates behind and maxed, I discovered that my old iPod Touch won't update to iOS7, so it's maxed, and my iPhone 5 updated normally.  So...  how do I juggle wh

  • Kernal_task takes me lot's of RAM

    Hi all I own a MacBook Air mid-2013 13" 128GB SSD and 4GB RAM. I recently noticed that the 'kernal_task' takes me lot of RAM (700 MB)... I would like to know what is 'kernal_task' and why does it takes me so much of my RAM? Thanks, Itay

  • Will Apple release the iPhone 5 headphones to the store?

    -Title-