Modulus with negative numbers

Slight problem using modulus. When I try to take the modulus of a negative number I get the original number back. An example is (-92%26) returns -92 rather than 12. Does anyone know a workaround??
Thnx~

In Java you can get two types of mod or remainder in the class BigInteger.
BigInteger b_92 = new BigInteger("-92");
BigInteger b26 = new BigInteger("26");
System.out.println(b_92.remainder(b26).toString());
System.out.println(b_92.mod(b26).toString());
System.out.println(String.valueOf(-92 % 26));

Similar Messages

  • Flex 2 Stacked Bars with Negative Numbers?

    Hi guys, the strangest thing: I have a client requesting
    sacked bars for bar charts/column charts however, I can't seem to
    get the negative numbers to go below a positive x-axis.
    Do these bug logs suggest I need Flex 3?
    https://bugs.adobe.com/jira/browse/FLEXDMV-921
    https://bugs.adobe.com/jira/browse/FLEXDMV-1181
    and if that's the case, how will upgrading effect my current
    project?
    Thank you.

    Great, as in another thread defined and discused, i am
    a scripter, not a programmer, but i like oaying with math.
    Daves method is easy, but what about Random( -300,1200).
    that must be a huge array to initialize.
    my function has a restriction:
    it works only, if there is a zero in the range or you'll
    never get the highest number of the range. Also it can only have a
    linear range.
    Dave can input a list like this gRandomChoises = [
    1,3,5,7,11,13,17] , what can be very usefull in some cases.
    Cheers,
    Wolfgang

  • Rounded corners BUT with negative numbers

    In illustrator it's very easy to round the corners of a rectangle. But what
    if you wanted to get the effect of a rectangle whose corners round inward
    instead of out. I've tried assigning a negative value to the rounded corner
    dialog box, but illustrator won't allow that. Would anyone know how to do
    this? It would be a great addition to illustrator to allow you to assign a negative value.

    Hi again,
    I tried with the FPGA_PID_LPFIR.vi and it works fine.
    There's no problem with negative setpoint.
    Attached file :
    This is a bit more complicated code since there's quadrature counter and SELECT in the pid loop.
    **I must point out the fact that there's a SELECT  between an int16 analog feedback and an u32 quadrature counter.
       I don't know if it can interfer with the int16 setpoint labeled in french "CONSIGNE_ENTREE"
       I can't do futher testing at this time because the FPGA is actually in production mode.
       But I'm setting up an other computer with the same model of FGPA (PCI-7833R) in order to investigate this problem.
    NICOLAS HUPPÉ,M.Sc.A, ing. jr.
    Groupe de Recherche PERSEUS
    Université de Sherbrooke
    Attachments:
    BIOMETISS_PID_LPFIR_FPGA.vi ‏2883 KB

  • Modulus giving negative numbers

    I'm trying to make a random number generator for C but I'm using Java at the moment since I don't have a C compiler at work. The problem I'm having is that java is giving negative numbers sometimes, when all I want is positive numbers. For example, when rand starts at 63242, it gives -12880 as the next random number. Is this just a java thing, or will this happen in C too?
    int rand = 2;
    int max = 65535;
    for(int c = 0; c < 100; c++){
      rand *= 35291;
      rand += 104729;
      rand %= max;
      if(rand < 0)
        rand = max + rand;                 
      System.out.println(rand);
    }

    I know of those, but I'm needing to make my own. I figured it out though, I'm going over the int limit, which it then gives me negative numbers. Thanks for your help though.

  • Plotting XY graphs - with negative numbers

    hi!
    i have two arrays..
    the array A and B
    i connected the 2 arrays with XY graph, because i want to plot the data contains to the two arrays
    the problem is that the XY graph don't plot the negative elements...
    why??
    thanks a lot!!
    andrikos

    These arrays were just indicators. You need to change the data itself. Easiest would be to insert "ToI32" after "boolean array to number".
    Message Edited by altenbach on 04-06-2008 05:03 PM
    LabVIEW Champion . Do more with less code and in less time .
    Attachments:
    ToI32.png ‏3 KB

  • Negative Numbers importing wrong

    I have a Stored Procedure on my SQL Server 6.5 DB that returns a list of decimal values (sql datatype is decimal(5,2)), of which most are Negative numbers. When the procedure is run in a SQL tool (MS Query or ISQL) the values are returned correctly. When the stored procedure is called in Java, all values (negative or positive) are showing up as zero.
    I have tried all of the following ...
    double d = rs.getDouble(1);
    Float f = rs.getFloat(1);
    Double d2 = new Double(rs.getDouble(1));
    BigDecimal b = rs.getBigDecimal(1);
    String s = rs.getString(1);The value returned by the procedure should look something like -14.75 but when using System.out.println(f.toString()); it is shown as ".00". I have even tried exporting the data out of Java into MS Excel to see if it is just something funny with the System.out.println() statement but it shows all zeros in Excel also.
    Is there anything special or a specific data type that must be used for negative numbers to read correctly in Java? I've searched the forum, tutorials and API (1.3) and haven't found anything like this.
    Any help would be greatly appreciated!!!

    So why do you say the error has something to do with negative numbers when (in your own words): "all values (negative or positive) are showing up as zero"? I don't know what your problem is, but negative numbers probably ain't it.

  • HFM 9.3 - FR Studio - can't format negative numbers with minus sign prefix?

    How can negative numbers on an account balance report be made to appear with a leading minus sign??
    This is a necessary requirement for generating an export file for loading to our new Tax software, but does not appear to be a format option.

    Have you tried going into Format Cells - Number - Negative Number Symbols - and typing a minus sign in the prefix box?

  • Numbers 3 summing cells with negative values

    I am trying to sum a column of cells with postive and negatve numbers but the result does not consider the the negative sign.  It just adss absolute values

    There is something else going on.  I can clearly sum positive and negative numbers:
    Please use this note to post a screenshot of the data in question:
    https://discussions.apple.com/docs/DOC-6591

  • Restrict Negative Numbers with Format Mask

    Hi
    Is it possible to restrict negative numbers by using format mask.
    rgds
    shabar

    Hi,
    Have you tried setting the Lowest Allowed Value to 0 ?
    -Arun

  • Is anyone having trouble using parenthesis to show negative numbers in excel after upgrading to Yosemite?

    Since upgrading to Yosemite, I can no longer reflect negative numbers with parenthesis using excel.  All of my existing spreadsheets also no longer show parenthesis, creating formatting problems.  Is anyone else experiencing this and is there a solution?

    I suggest you post your question to Microsofts own forums for their Mac software as it's their product you're having issues with
    http://answers.microsoft.com/en-us/mac

  • How do I disallow negative numbers in a selected group of cells (i.e. only allow values greater than or equal to zero)?

    I have a table of calculated values in Numbers, and I want to disallow negative numbers in the entire table. Any numbers that would be negative I would like changed to/displayed as zeroes, that way future calculations that may be based on this cell use the value of 0 for the calculation rather than the negative value. I have seen ways of doing this to single cells at a time, but I am interested in applying it to a large selection of cells.
    There is the Conditional Format option when you bring up the inspector, but I cannot get a custom rule to work for me. I select "Greater than or equal to" and I enter 0 in the box, but nothing changes. Can anyone help with this?
    Thanks

    A step toward simplifying the application of MAX to the issue, Jerry.
    This part, though:
    Now apply your long, animal-modeling, expressions to this new, interposing, table rather than the original.
    may still leave several references to be change from the original data table to the new one.
    One way to get around that is to use the Duplicate ("DATA-1) as the new table for raw data, and the Original (DATA) as the interposing table, using the formula =MAX(DATA-1::A2) as above, starting in DATA::A2.
    This way, the long expressions could continue to reference the original table (with its content now modified).
    ALTERNATE process:
    Find/Replace could also be used to speed the process of reassigning the modeling expressions to the duplicate table, as suggested by Jerry. But some cautions apply here.
    Find/Replace can be limited to Formulas only, but not to Some formulas only.
    Find/Replace can be limited to the Current Sheet only, but this can't be combined with Formulas only.
    More on this later, when I've had a chance to check some possibilities.
    Regards,
    Barry

  • In range and coerce with complex numbers?

    I have an array of complex numbers with these numbers I need to set to 0 all numbers whose real parts are negative. With "in range and coerce" I can split the array into real and imaginary then set all negative numbers to 0 then recombine the complex part but that still leaves me with 0+ai numbers that should be 0. How can I also set the complex part to zero for the negative numbers?

    Hello,
    You can use the following fonction in a for loop with your array.
    Michel

  • Negative numbers in export to excel

    Hi,
    We have two servers, one (X) without SP1 and the other (Y) with SP1.
    When I make export to excel in X, the negative numbers sometimes saved as @ or the actual negative number (e.g. -42), in both cases it is saved as text.
    The positive numbers are saved as numbers.
    We saw that SAP fixed it in SP1, we tried it on Y, we got that the negative numbers always show (e.g. -42), but all the numbers, positive and negative are saved as text.
    We need to see all the actual numbers(without @), and to be saved as numbers (so we can make calculations on them).
    Does anyone have any idea?
    Thanks.

    I am on SP1 and noticed that sometimes they are saved as numbers and some are texts:
    So I am not sure of any logic or what is going on.
    Maybe as a work around you could format everything to numbers so you can do the calculation?

  • Working with Large Numbers

    Hi there,
    I am currently doing a school assignment and not looking for answers but just a little guidance.
    I am working with large numbers and the modulo operator.
    I might have some numbers such as :
    int n = 221;
    int e = 5;
    int d = 77;
    int message = 84;
    int en = (int) (Math.pow(message, e) % n);
    int dn = (int) (Math.pow(en, d) % n);Would there be a better way to do this kind of calculation. The dn value should come out the same as message. But I always get something different and I think I might be losing something in the fact that an int can only hold smaller values.

    EJP wrote:
    It might make sense in some contexts to have a positive and negative infinity.
    Yes, perhaps that's a better name. Guess I was harking back to old COBOL days :-).(*)
    But the reason these things exist in FP is because the hardware can actually deliver them. That rationale doesn't apply to BIgInteger.Actually, it does. All I'm talking about is a value that compares higher or lower than any other. That could be done either by a special internal sign value (my slight preference) or by simply adding code to compareTo(), equals() and hashCode() methods that takes the two constants into account (as they already do with ZERO and ONE).
    Don't worry, I'm not holding my breath; but I have come across a few situations in which values like that would have been useful.
    Winston
    Edited by: YoungWinston on Mar 22, 2011 9:07 AM
    (*) Actually, '&plusmn;infinity' tends to suggest a valid arithmetic value, and I wasn't thinking of changing existing BigInteger/BigDecimal maths (except perhaps to throw an exception if either value is involved).

  • Negative Numbers considered as VARCHAR while uploading CSV file under Data Load in APEX

    I am trying to upload a CSV file which contains negative numbers. These negative numbers are being considered as VARCHAR2 while uploading. And if I change the Column Type to Numbers the upload fails.
    Any solutions the problem will highly be appreciated.

    select * from nls_database_parameters
    where parameter = 'NLS_NUMERIC_CHARACTERS'
    shows you which characters your database believes represent the decimal place and the thousands separator. So, if your database expects 1,234.123 and you present a 'number' as 1 234,123 it will complain.
    Also, in your case... your comma-separated-values contain commas? Or are the individual fields enclosed with quotes?

Maybe you are looking for

  • Problem while Binding multiple Parameters to View Object[Solved]

    Hello, I am facing problem while binding multiple parameters with different data types in View Object query. For example suppose I have following query in my view object. SELECT Header.ADDED_BY Header.BATCH_ID, FROM BATCH_HEADER Header WHERE :1='dept

  • I tunes 8 constantly asking for authorization, then says already authorized

    Ever since I downloaded itunes 8.0, it has been constantly asking me to authorize songs- after which it says the computer is already authorized- I thought it was a quirk with the download, so I re-downloaded and installed 8.0, but I"m having the same

  • Problems with the CONTACTS in iPhone

    i'm using a iPhone-4 n i recently updated my iOS to 5.1; the software was succesfully updated but then later on i'm not getting the EDIT option in ma contact list need help

  • When I play a video in fullscreen using flash, it always opens on my primary monitor

    Hi, About 2 days ago this problem started, anytime I open a video in fullscreen, it opens up on my primary monitor rather than the monitor that the browser window is on. Also i have only just noticed that flash videos arent working on firefox (don't

  • Flash CS4 crashes at startup

    I have recently purchased CS4 Design Premium. The installation of all applications went fine (no error message) and all applications work perfect except Flash CS4. On startup I see shortly the stage screen and then the spinning beach ball. I tried un