Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

Is the% of the RokcetMq source code complementary or modular?

2025-01-18 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >

Share

Shulou(Shulou.com)06/01 Report--

This article mainly explains the "RokcetMq source code in% is redundant or modular", the content of the explanation is simple and clear, easy to learn and understand, the following please follow the editor's ideas slowly in-depth, together to study and learn "RokcetMq source code% is redundant or modular" it!

Background

When many students see my title, they can't help but say: are you teasing me? isn't it the same thing to ask for surplus and take a mold? Yes, not long ago, I felt the same as you. Isn't it the same thing to ask for surplus and take a mold? Until one day, when a group friend was reading the RokcetMq source code again, he found the following code:

Private static int initValueIndex () {

Random r = new Random ()

Return Math.abs (r.nextInt () 999) 999

} surplus or module?

If we take a closer look at the above code, we find that Math.abs is used, and this function represents an absolute value, which means it has something to do with symbols, although the r.nextInt here cannot be negative, maybe the developers at that time understood that this function might have negative numbers (in fact, r.nextInt would not have negative numbers), so they took absolute values.

So what does this have to do with our title redundancy and modeling? Don't worry, let's take a look at the following formula:

1. Find the integer quotient: C = a _ b

two。 Calculation module or remainder: r = a-cymb.

Both the remainder and the modulus are calculated using these two formulas, but they are different when they calculate the integer quotient in the first step. when taking the c value, the remainder operation is rounded to 0, and the module operation is rounded to the infinitesimal direction when calculating the c value. it should be noted here that the remainder operation is not rounded to infinity, why, because when an and b are consistent, they will round down. But the remainder will be rounded up and the module will be rounded down when the symbol of b is different, and finally the modular operator will be the same as b, and the budget of remainder will be the same as a.

Generally speaking, the symbol "cre" means "surplus" and "python" is a module.

In our above code, the author obviously wants to implement the module, that is, when b is a positive number, then the value of the module will always be positive.

But how do we implement modeling in Java? This function Math.floorMod is provided in Math, which is used for module fetching. We have the following code for verification:

Public static void main (String [] args) {

System.out.println ("take the mold" + Math.floorMod (3,-5))

System.out.println ("surplus" + 3%-5)

}

Take mold-2

Qiu Yu 3

You can see that the output is in line with our expectations.

Thank you for your reading, the above is the content of "RokcetMq source code is redundant or modular". After the study of this article, I believe you have a deeper understanding of the question of whether% of RokcetMq source code is redundant or modular, and the specific use needs to be verified in practice. Here is, the editor will push for you more related knowledge points of the article, welcome to follow!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Internet Technology

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report