eupolicy.social is one of the many independent Mastodon servers you can use to participate in the fediverse.
This Mastodon server is a friendly and respectful discussion space for people working in areas related to EU policy. When you request to create an account, please tell us something about you.

Server stats:

215
active users

#float

0 posts0 participants0 posts today

So I have both float->#minifloat and minifloat->#float conversion in my #CommonLisp minifloat library now. And a lot of constants—NaNs, infinities, most and least representable floats etc. It's basically ready, though severely untested. But hey, I didn't expect I can ever make a float decoding library, let alone in under one month!

I still have to find better algorithms. Some forgotten corners of the academic Internet have pearls of wisdom and I'll eventually find them. But, for now, my algorithms are alright too, running mostly in nanoseconds.

Find it at codeberg.org/aartaka/cl-minifl

Summary card of repository aartaka/cl-minifloats
Codeberg.orgcl-minifloatsImplementation of minifloats (<=8 bit floats) for Common Lisp

The water level in the canal dropped a bit overnight. I realised this when I noticed the boat was listing away from the bank, and only rocking along one axis instead of the usual three.

Closest to the bank, the bottom of the boat was touching ground, underwater.

My neighbour helped me refloat, pushing out the boat while I leaned and swung on the far gunnel to make the boat lift clear of the underwater ground.

Як же мене після C++ навіть на Python тягне оптимізувати там де ніхто не звертає уваги. До прикладу багато хто використовує всюди списки дам де це не потрібно і можна взяти кортеж.

Обʼєкт типу object займає 16 BYTES. Це можна дізнатись викликавши метод __sizeof__ в обʼєкта.

o = object()
o.__sizeof__()

Від цього типу наслідуються всі інші стандартні й не тільки типи навіть якщо явно цього не вказано. Тому це найменший можливий розмір будь-якого обʼєкта. Перевірити це можна за допомоги функції issubclass яка приймає два типи та повертає значення типу bool.

>>> issubclass(int, object)
True
>>> issubclass(float, object)
True
>>> issubclass(bool, object)
True
>>> issubclass(str, object)
True
>>> issubclass(list, object)
True
>>> issubclass(tuple, object)
True
>>> class A:
...     pass
... 
>>> issubclass(A, object)
True

Саме через це всі обʼєкти мають функцію __sizeof__ і не тільки.

Якщо ми подивимось на розміри стандартних типів, то можемо трохи здивуватись.

>>> int().__sizeof__()
28
>>> float().__sizeof__()
24
>>> bool().__sizeof__()
28
>>> str().__sizeof__()
49
>>> tuple().__sizeof__()
24
>>> list().__sizeof__()
40
>>> set().__sizeof__()
200
>>> dict().__sizeof__()
48

Найбільше я здивувався розміру типу bool. Він займає скільки ж як і int, і є більшим за float та tuple. І це все розміри порожніх (нульових) обʼєктів.

Тепер порівняємо кортежі та списками з однаковим вмістом.

>>> t = (1,2,3,4,5,6)
>>> l = [1,2,3,4,5,6]

>>> t.__sizeof__()
72
>>> l.__sizeof__()
88

Різниця та ж що й при порожніх контейнерах через те що контейнер зберігає тільки посилання на обʼєкт. Можемо в цьому переконатись за id обʼєктів.

>>> id(t[0]) == id(l[0])
True
>>> t[0] is l[0]
True

Оператор is робить те саме, він порівнює ідентифікатори.

Це добре що python оптимізує програму не створюючи зайвих обʼєктів, але всеодно всі обʼєкти займають дуже багато місця. Саме через це я й ненавиджу такі мови як python, js...

#програмування #python #sizeof #розміри #типи #int #float #list #tuple #списки #кортежі #sizeof #object #оптимізація #бісить

social.net.uaSocial.Net.Ua