![]() ![]() The general guideline is that every class should have both state (data) and behaviour (one or more methods). The classes often don’t do anything except hold that method. In Java, every function has to be put into a method of some class. It reads like you are trying to program Java in Python. Its probably just a case of somebody thought it was a good idea at the time.īy the way, each of the builtin exponent operator **, the pow() builtin function, and math.pow function round 2.0 to the power of (negative huge number) to 0.0.īy the way, you have two classes which do nothing and exist for no reason other than to hold a function. There’s probably no real logic behind the difference. Floating point multiplication in Python must follow the rules set up by the IEEE-754 standard, which has multiplication overflow to the special value float(‘inf’).īut for reasons now lost, whoever designed Python’s exponent operator, and the pow() function, made a different decision to raise OverflowError instead. That is probably buried deep, deep in the mists of history, when Python was first written. Why the difference between multiplication and exponentiation? Which rounds to zero, so you get the final result of 0.0. For brevity I won’t write them all down in full: While the second computes the similar sequence, but using multiplication. Your first method tries to compute the sequence of powers: The two methods behave differently because they are written differently, one uses the exponentiation operator ** and the other just uses multiplication. ![]()
0 Comments
Leave a Reply. |
Details
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |