Skip to content

Clarify meaning of floating point m.room.power_levels#2297

Open
velikopter wants to merge 7 commits intomatrix-org:mainfrom
velikopter:floating-pls
Open

Clarify meaning of floating point m.room.power_levels#2297
velikopter wants to merge 7 commits intomatrix-org:mainfrom
velikopter:floating-pls

Conversation

@velikopter
Copy link
Contributor

@velikopter velikopter commented Jan 25, 2026

Not sure if I did this the right way..

Pull Request Checklist

Signed-off-by: Kierre Sametti vel@riseup.net

Preview: https://pr2297--matrix-spec-previews.netlify.app

@velikopter velikopter requested a review from a team as a code owner January 25, 2026 16:32
@richvdh richvdh changed the title m.room.power_levels events accept values as floats Clarify meaning of floating point m.room.power_levels Jan 28, 2026
Co-authored-by: Richard van der Hoff <1389908+richvdh@users.noreply.github.com>
Co-authored-by: Richard van der Hoff <1389908+richvdh@users.noreply.github.com>
@@ -0,0 +1,34 @@

##### `m.room.power_levels` events accept values as floats
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see we already have a section about stringy power levels. Is it the case that strings representing floats are accepted here too? In other words, are "5.17" and "1.34E3" accepted?

If so, we should probably combine the two sections into a single "m.room.power_levels events accept values as strings or floats" section.

If not, we could do with a clarification in the stringy power levels section.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

floating-point powerlevels aren't allowed in strings:

>>> int("5.63")
Traceback (most recent call last):
  File "<python-input-1>", line 1, in <module>
    int("5.63")
    ~~~^^^^^^^^
ValueError: invalid literal for int() with base 10: '5.63'
>>> 

I will add a clarification in that section.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe this is already described well:

a single base 10 integer, no float values or decimal points, optionally with any number of leading zeroes ("100", "000100");

(emphasis mine)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Right, yes.

I think the bit that's confusing me is the words "When the value is representative of an integer", which makes it sound like we haven't decided what to if the string contains something that isn't an integer.

I think it should probably say something like:

For fields where the schema for m.room.power_levels specifies an integer, a string complying with the following rules is also permitted:

@richvdh
Copy link
Member

richvdh commented Jan 28, 2026

(Thanks for taking this on!)

@richvdh
Copy link
Member

richvdh commented Jan 28, 2026

Related: #1244

@richvdh
Copy link
Member

richvdh commented Feb 3, 2026

Question: how is a power level of 99.999999999999999 handled?

Or, since we're talking edge cases, 1e400 ?

@velikopter
Copy link
Contributor Author

Question: how is a power level of 99.999999999999999 handled?

Or, since we're talking edge cases, 1e400 ?

>>> int(1e400)
Traceback (most recent call last):
  File "<python-input-0>", line 1, in <module>
    int(1e400)
    ~~~^^^^^^^
OverflowError: cannot convert float infinity to integer
>>> int(99.999999999999999)
100
>>> 

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants