HISE Logo Forum
    • Categories
    • Register
    • Login

    Is there a way to do big calculations without hitting integer overflow?

    Scheduled Pinned Locked Moved General Questions
    3 Posts 2 Posters 213 Views
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • C
      cynthasiser
      last edited by

      Hi there, new to HISE and fairly new to coding so this might be a dumb question, but I'm wondering if there's any way to calculate higher numbers before they go negative?

      I'm working on a program to help visualise different tuning systems; you set a tuning system and it shows you how it maps to the keyboard and gives you live information on the ratios between the notes you're playing.

      However, if you use a scale which is an equal division of an interval, such as 12 divisions of the octave, the main one used for western music, the pitches are in ratios of irrational numbers. I want to show users an approximation of the closest pure ratios to these irrational intervals and I've done it like this:

      Find the closest approximate fractions to the cent value of the irrational interval e.g. 1/1, 20/19, 17/13, 12/7....

      Multiply the set by each unique denominator, so that they're all integers e.g. 1729, 1820, 2261, 2964...

      Then display as usual, doing real-time calculation to reduce the ratios e.g. if you played the 20/19 note and the 12/17 note at the same time, 1820 and 2964 reduce to 35:57, which is more useful to look at than these huge numbers.

      The problem is the multiplication step can get out of hand very quickly, especially if you have a 10+ note scale, and hits the 2 billion integer overflow quite easily.

      My best fix is to limit the approximation step to smaller fractions, making less accurate approximations but more manageable numbers. Before I commit to this I just wanted to ask if I can increase the integer overflow limit, or is this a hard rule in programming?

      Thanks!

      LindonL 1 Reply Last reply Reply Quote 0
      • LindonL
        Lindon @cynthasiser
        last edited by

        @cynthasiser well integer overflow is pretty much fixed, so to get around it most of the time we calculate in floating point and flip to integer at the end....

        HISE Development for hire.
        www.channelrobot.com

        C 1 Reply Last reply Reply Quote 1
        • C
          cynthasiser @Lindon
          last edited by

          @Lindon Okay, thank you! That's kind of what I'm doing but I guess the problem is I actually need the giant numbers because I'm working with exact integer ratios. I think I've found a better way of approaching the problem though, as I got it working with the smaller approximations and the behaviour wasn't quite what I wanted anyway.

          1 Reply Last reply Reply Quote 0
          • First post
            Last post

          46

          Online

          1.7k

          Users

          11.7k

          Topics

          101.8k

          Posts