Chapter 100 (1/2)

Compared with Academician Zhan Yongshu's surprise, Hao Yun didn't think about it when he thought about it. It was just a brainwave when he scratched his head.

The program first guesses a value close to 1 / sqrt (number), and then uses Newton's iterative formula for iterative operation.

Just from the logic of the algorithm, in fact, his rewritten code is the same as the previous Q_ The code for the sqrt function doesn't make much difference. Q defined by glacier engine in math. C file_ Sqrt function, in fact, also uses this idea.

The only difference is probably in the mysterious number - 0x5f375a86.

According to the principle of Newton iterative algorithm, the closer the guess is to the final result, the fewer iterations. The mysterious number 0x5f375a86 is used to calculate the guess value.

After several attempts, Hao Yun unexpectedly found that if he used the number ”0x5f375a86”, the obtained y would be very close to 1 / sqrt (n), so that when he finally implemented the Newton iterative algorithm, he only needed two iterations to achieve the accuracy he needed!

How did you get this number?

Hao Yun can't explain.

After all, he just followed his own mathematical intuition, felt that the number selected in the original program was not good enough, and then tried to change to a better number.

At the beginning, he tried several times and found that the changed number was not as easy to use as the original one. Later, he got an idea and tried this 0x5f375a86. He found that it took only two iterations to complete the whole calculation process.

To be honest, he was not surprised.

Maybe

Does it have something to do with his mastery of mathematics?

In a word, after using the special number of 0x5f375a86, the operation efficiency of the whole function will be higher than that of Q defined in the original math. C file_ The sqrt function is twice as fast!

As for the effect of this result

To be honest, Hao Yun does not have an accurate concept.

After all, his understanding of this glacier engine is far from that of the industry.

Although he had played games before, he only played 2048. Temple Escape is a kind of development software with the same origin as glacier engine, but that game was basically completed by Li Zongzheng alone. Hao Yun didn't participate in the development at all. Even if he participated in it, he would not study the source code of the engine.

The game development tools in this world have evolved to a fool's degree. Apart from those big productions, most of the small and medium-sized games can only be realized by relying on development tools and secondary programming level.

”... in other words, how much has the efficiency of the test engine been improved? Is there no scoring software or testing game on this computer? ”

Hao Yun searched the computer carefully, but he didn't find the tool software that can be used to score the engine, nor the game that can test the performance of the engine.

In fact, the organizers did not prepare such things.

After all, from the beginning, they didn't even consider that someone could really complete this proposition.

”I'll go. Is it wool?”

After searching for some time, we still can't find the detection tool. Hao Yun looks at the screen with tears and smiles, and there's no way out.

Can't you develop a game on the spot to run points?

It's not that bad, but I don't have any material at hand, and computers can't be connected to the Internet. I can't start with the most basic material, can I?

After some entanglement, Hao Yun finally gave up.

forget it.

Anyway, I can't think of a better optimization method

Thinking about this, Hao Yun sighed, reached for the submit option in the examination program, and then left the keyboard with both hands - the so-called AK.

The examination only set a three-day maximum time limit, and did not set a minimum time to hand in papers, submitted answers can leave at any time.

Because even if you hand in the paper ahead of time, you won't get extra points, so even if you finish it ahead of time, most people will choose to cook until dinner time to hand in the paper, and go out to dinner with the friends who come with you.

Hao Yun planned to do the same at the beginning, but there was nothing in his compartment. He had nothing to do except sit and wait, so he had to come out of his compartment.

When I left the examination room, the security guard was still standing at the entrance.

Hao Yun glanced at him, and he also stared at Hao Yun for a while.

”Go to the bathroom? You're going in the wrong direction. ”

”No, I finished.”

”Test, finished?”

”Well,” Hao Yun nodded and pointed to the exit of the gymnasium, ”may I go out?”

Finally, he recovered from the stupefied spirit. The security guard's little brother Mu lowered his head and untied the isolation belt at the entrance.