Clarify meaning of floating point m.room.power_levels#2297
Clarify meaning of floating point m.room.power_levels#2297velikopter wants to merge 7 commits intomatrix-org:mainfrom
m.room.power_levels#2297Conversation
2700d99 to
b09d59b
Compare
m.room.power_levels events accept values as floatsm.room.power_levels
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 | |||
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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)
There was a problem hiding this comment.
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_levelsspecifies an integer, a string complying with the following rules is also permitted:
|
(Thanks for taking this on!) |
|
Related: #1244 |
this makes more sense to me
|
Question: how is a power level of Or, since we're talking edge cases, |
>>> 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
>>> |
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