Module talk:Math

This module implements a collection of related mathematical operations and number formatting tasks.

bug "�"
Hello, this is not enwiki problem. On bnwiki, this module sometime gives incorrect result. There is problem with "precision_format". For example, gives ২�000 instead of ২,০০০ (more example, bn:Module:Math, sandbox). How can i fix this? Please feel free to edit sandbox. --আফতাবুজ্জামান (talk) 23:56, 2 June 2020 (UTC)
 * @আফতাবুজ্জামান: That bug is due to the following optimistic code:

local zero_sep = lang:formatNum(1.1) formatted_num = formatted_num .. zero_sep:sub(2,2)
 * The code is trying to determine the character for the decimal point (for example,  or  ). The code assumes the local number uses English digits in which case   will extract the second character which they hope is   or  . However, at bnwiki 1.1 is ১.১ and the code gets the second byte of the first digit which gives that broken Unicode symbol. A simple fix would be to change the above by commenting out or deleting the first line, and editing the second line:

--local zero_sep = lang:formatNum(1.1) formatted_num = formatted_num .. '.'
 * A bit more clever would be to rearrange it to use mw.ustring.sub but that's pointless for you because you know you want a dot. The result is going to use en digits. There's not much that can be done about that apart from the conversion code that we have discussed in the past. Johnuniq (talk) 05:09, 3 June 2020 (UTC)
 * Thanks. Problem resolved. Everything is giving correct result but for some reason is giving incorrect result. আফতাবুজ্জামান (talk) 03:02, 4 June 2020 (UTC)

@আফতাবুজ্জামান:Hmm, that seems to be a bug in lang:formatNum. Put the following in a module sandbox and test with. local function main local lang = mw.getContentLanguage local r = lang:formatNum(0.00002) return #r .. ' /' .. r .. '/' end return {main=main} Trying this gives the results shown: The 7 is the length (number of bytes) in the result. Each of the two bn digits is 3 bytes in UTF-8 and the dot is 1, so they add up to 7. The point of that is that there is nothing in the output that is hidden—it's only 7 bytes. I guess you could ask about that at Phabricator. Perhaps e notation is not supported in a language where it is not usually used? Is it used? Johnuniq (talk) 03:59, 4 June 2020 (UTC)
 * At bnwiki: 7 /২.০/ (in en digits, that's "7 /2.0/")
 * At enwiki: 6 /2.0E-5/
 * Ya, e notation is uncommon in Bengali. I'm not sure what should i request when submitting a bug for this. If you can, please do. Anyway, after spending many hours i was able to do this, it seems this fixes the problem. Should i implement? --আফতাবুজ্জামান (talk) 00:44, 7 June 2020 (UTC)
 * @আফতাবুজ্জামান: That change looks good, well done! I examined the code as far as your change goes but deciding that the overall function always works would be mind-spinnnig stuff which is why I didn't dive in earlier. Re my earlier comment about a bug, if you link to a module sandbox I could create (it would be Module:Sandbox/Johnuniq/format here) I'll probably try reporting it. Johnuniq (talk) 01:29, 7 June 2020 (UTC)
 * Thanks. here. আফতাবুজ্জামান (talk) 01:45, 7 June 2020 (UTC)
 * @আফতাবুজ্জামান: I posted at T254683. Johnuniq (talk) 07:45, 7 June 2020 (UTC)

I see that a software update since the above has changed what occurs. bn:Module talk:খেলাঘর/Johnuniq/format used to show that  gave the bn equivalent of "2.0" (wrong) while here at enwiki it gave "2.0E-5". Now, both results are the equivalent of "0". Some consequences: Johnuniq (talk) 06:26, 11 January 2021 (UTC)


 * @Johnuniq Can you tell me the file I should touch for this code?  Nokib Sarkar  knock 15:41, 6 July 2024 (UTC)
 * Sorry, the above was 3.5 years ago and I have no recollection of the details. I think I decided that there was a bug in the way certain formatting was done at bnwiki and reported it in the above phab link. As mentioned above, a subsequent change removed the worst of the bug but left this module doing strange things with certain values. I have only done one edit at Module:Math and that was for a routine fix. Is there a problem at bnwiki? Is there an example showing the problem? Has it been discussed there? Johnuniq (talk) 01:24, 7 July 2024 (UTC)
 * @Johnuniq Actually, I was trying to clear the backlogs for my native language Bangla Wikipedia and it was still open.  Nokib Sarkar  knock 07:13, 7 July 2024 (UTC)
 * @আফতাবুজ্জামান is it relevant still?  Nokib Sarkar  knock 08:28, 7 July 2024 (UTC)
 * @Nokib Sarkar, আমার এই মূহুর্তে মনে পড়ছে না। I don't remember. আফতাবুজ্জামান (talk) 17:03, 9 July 2024 (UTC)

Protected edit request on 10 March 2021
Please copy from Module:Math/sandbox to implement the merge of Module:PassMath per Templates for discussion/Log/2021 February 28 * Pppery * it has begun... 20:14, 10 March 2021 (UTC)
 * Yes check.svg Done Primefac (talk) 18:09, 11 March 2021 (UTC)
 * Note that I made a typo in a comment when implementing this merge. It's probably not worth making an edit to a module this highly used to correct it, but I've fixed it in the sandbox. * Pppery * it has begun... 20:34, 11 March 2021 (UTC)
 * Given that it's instructions (though I will say buried outside of the /doc) it could potentially cause issues, so I've updated it. Primefac (talk) 22:24, 11 March 2021 (UTC)

lang:formatNum fix for small numbers of order -5 and smaller
lang:formatNum for numbers of order -5 and smaller returns 0 (for en language). Temporary(?) fix in lua pseudocode: Context: Template_talk:Round. MarMi wiki (talk) 19:49, 26 April 2021 (UTC)


 * Implemented in sandbox. MarMi wiki (talk) 15:21, 27 April 2021 (UTC)

Rounding in the module and rounding in the expr
p._round function.

For 0.005 it returns: invoke, expr

For -0.005 it returns: invoke, expr

Called by: ,

What type of rounding function exactly it is supposed to be? It looks like half up rounding, which doesn't match the rounding used by expr. Is that intentional? MarMi wiki (talk) 19:10, 27 August 2023 (UTC)