Sujet : Re: Need Assistance -- Network Programming
De : ldo (at) *nospam* nz.invalid (Lawrence D'Oliveiro)
Groupes : comp.os.linux.advocacyDate : 27. Jun 2024, 10:01:28
Autres entêtes
Organisation : A noiseless patient Spider
Message-ID : <v5j68n$2ks7o$7@dont-email.me>
References : 1 2 3 4 5 6 7 8 9
User-Agent : Pan/0.158 (Avdiivka; )
On 26 Jun 2024 23:58:30 GMT, rbowman wrote:
Similarly while Python has math.degrees() and math.radians() ...
I’ve long felt those conversion functions are an unnecessarily roundabout
way of doing things. After all, you need two for every angle unit,
assuming you stick with radians as the common basis among all of them.
Otherwise you need even more.
Better to have a single conversion factor for each unit, e.g.
class ANGLE_UNITS(float, enum.Enum) :
"standard values for Context.angle_units."
RADIANS = 1.0
DEGREES = math.pi / 180
GRADIANS = math.pi / 200
CIRCLE = 2 * math.pi
#end ANGLE_UNITS
so you multiply by the factor to convert the units to radians, and divide
by the same factor to convert radians to those units.
Then all your trig functions can operate exclusively in radians:
units = ANGLE_UNITS.DEGREES
θ = float(input("Angle in degrees? "))
x = math.sin(θ * units)
print("Angle: ", math.asin(x) / units, "°")
And yes, Python does full multiple inheritance. And yes, you can subclass
from builtin types like float as well. And further yes, enums are not a
built-in language feature, they are provided in a library module that is
written in pure Python.