Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 4321332
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T08:44:00+00:00 2026-05-21T08:44:00+00:00

There is a simple plain math formula for data alignment contained in the assembly

  • 0

There is a “simple” plain math formula for data alignment contained in the assembly source code of TinyPE, from this address:

http://www.phreedom.org/solar/code/tinype/

This is the formula:

%define round(n, r) (((n+(r-1))/r)*r)

I know that its main intention is to get numbers like n=31 aligned to something like round(n,r)==32 when r=8.

I know that n represents the intended number and r is the rounding “base” multiple. I also know that, given it is simple assembly source code, all operations return integer numbers only, so any decimals are conveniently lost and thus don’t cause any calculation “errors”.

The question is whether the following explanation is accurate, or if there is a better, more correct one. I don’t want to blindly use a snippet I could be misunderstanding somehow.

Also, I would have liked to use number+(round%(number%round)), but it causes division by zero when “number” is an exact multiple of “round”.


This formula gets the nearest multiple of a number which is power of two:

In this example our number is 31 and the number we want to have as “base” multiple is 8. It returns 32:

(((31+(8-1))/8)*8)

First we get 8-1, which gives 7. We add it to 31, which gives 38.

Then we divide 38/8, which gives 4.75. From this, the integer value is 4.

This 4 is multiplied by 8, which gives 32.

The logical/mathematical intention of each of these formula parts is as follows:

— The 8-1 parts makes that an excess be present, whether the original number (in this case 31) is a multiple or not of the base rounding number (in this case 8), and that gives a range that goes through 7 non-multiple numbers and a possible multiple. The -1 causes that we don’t get the wrong calculation by going right to the next non-nearest multiple but it just gives an inexact margin to detect the rest of previous “factors”.

— By dividing this exceeded number by the base multiple (8 in this case), in its integer part, we get only the previous factors. The excess that we add to it makes that the number gets aligned to the nearest multiple, if it’s within the immediate range without going up to two multiples ahead (hence the -1).

— By multiplying the purely integer part of this factor (4 in this case) by the base multiple r (8 in this case), we get the exact nearest multiple, without going to the next one. For instance the nearest multiple of 8, starting from 31, is 32, not 40.

  • 1 1 Answer
  • 3 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-21T08:44:00+00:00Added an answer on May 21, 2026 at 8:44 am

    I am not quite sure I understand your question, but if you wish to find the power of n closest to a given number x you could try

    n^(round(ln(x)/ln(n))

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I often have this kind of situation - there's a simple plain class, say,
Is there a code formula for this? I am using C# and XNA, and
Is there any simple way to get amount of data transferred from database to
I have a simple three table reference. It looks plain enough. The associations there
Is there a simple way, possibly with open-source command line tools in Linux, to
Plain and simple: is there a way to read (not run) .sas files on
Are there simple libraries out there (.NET and Java) that are able to validate
There is simple cipher that translates number to series of . ( ) In
There is simple JSON serialization module with name simplejson which easily serializes Python objects
Is there a simple way to insert the current time (like TIME: [2012-07-02 Mon

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.