Conversation
We had a wrong logic assuming, that low surrogate comes before the high surrogate, while the reverse is true. This caused an errorneus output of `String#chars` function etc. while iterating over character that is over the BMP, that is, has a Unicode codepoint over 0xffff.
A little known thing about JavaScript is that it uses UTF-16 encoding for its strings. But to leverage full extent of UTF-16 support, one must use correct functions, otherwise we are left with not supported over-the-BMP characters, like now ubiquitous emoji. This commit also makes most regexps use Unicode mode. Due to the Unicode mode regexps being more strict, we now really need a half a decent transpiler. That's also what it adds and using that situation, we also add support for POSIX character classes, which are quire often used in Ruby, but aren't there in JS, so we simulate them with Unicode character classes. As a side effect, this made us support value omission for hashes when compiling with Opal in JS (eg. when using `eval`). Since all the MSpec tests do this, we pass the tests now. We also add a proper support for multiline regular expressions. Semantics between how multiline works in Ruby and JS is very big, as in, those are basically two different features. This commit aims to reconcile those two features in the most straightforward way. This commit introduces quite proper handling of all "\A", "\z", "$", "^". It is our opinion, that a regexp will contain only one set of those in which case things will work correctly. If not, then we launch a warning. Regexps are now annotated if needed. This means, that if a certain regexp has been transpiled and the transpilation result differs, the copy of the original Regexp will be preserved, so that further manipulations on that Regexp, for instance `Regexp.union`, will work on an original Regexp. This PR has been sponsored by Ribose Inc.
|
@hmdne are you okay with this? Thanks! |
|
Looks good to me. I will backport it to the |
|
In short, all is fine, a couple of additional Rubyspec tests are passing now (https://github.com/ruby/spec/tree/ee83ee683bf15bb2bdd98498069f298abefbdbcc is the repo): fails "BigDecimal#** 0 to power of 0 is 1" # NoMethodError: undefined method `**' for 0
fails "BigDecimal#** 0 to powers < 0 is Infinity" # NoMethodError: undefined method `**' for 0
fails "BigDecimal#** other powers of 0 are 0" # NoMethodError: undefined method `**' for 0
fails "BigDecimal#** powers of 1 equal 1" # NoMethodError: undefined method `**' for 1
fails "BigDecimal#** returns 0.0 if self is infinite and argument is negative" # NoMethodError: undefined method `**' for Infinity
fails "BigDecimal#** returns NaN if self is NaN" # NoMethodError: undefined method `**' for NaN
fails "BigDecimal#** returns infinite if self is infinite and argument is positive" # NoMethodError: undefined method `**' for Infinity
fails "BigDecimal#fix correctly handles special values" # NoMethodError: undefined method `fix' for Infinity
fails "BigDecimal#fix does not allow any arguments" # Expected ArgumentError but got: NoMethodError (undefined method `fix' for 1.23456789)
fails "BigDecimal#fix returns 0 if the absolute value is < 1" # NoMethodError: undefined method `fix' for 0.99999
fails "BigDecimal#fix returns a BigDecimal" # NoMethodError: undefined method `fix' for Infinity
fails "BigDecimal#fix returns the integer part of the absolute value" # NoMethodError: undefined method `fix' for 2e+1000
fails "BigDecimal#power 0 to power of 0 is 1" # NoMethodError: undefined method `power' for 0
fails "BigDecimal#power 0 to powers < 0 is Infinity" # NoMethodError: undefined method `power' for 0
fails "BigDecimal#power other powers of 0 are 0" # NoMethodError: undefined method `power' for 0
fails "BigDecimal#power powers of 1 equal 1" # NoMethodError: undefined method `power' for 1
fails "BigDecimal#power returns 0.0 if self is infinite and argument is negative" # NoMethodError: undefined method `power' for Infinity
fails "BigDecimal#power returns NaN if self is NaN" # NoMethodError: undefined method `power' for NaN
fails "BigDecimal#power returns infinite if self is infinite and argument is positive" # NoMethodError: undefined method `power' for InfinityBut also there are new failures, which probably were disabled due to missing functions, some of which you may want to correct for better compatibility. fails "BigDecimal#truncate returns NaN if self is NaN" # ArgumentError: [BigDecimal#fix] wrong number of arguments (given 1, expected 0)
fails "BigDecimal#truncate returns value of type Integer." # Expected false == true to be truthy but was false
fails "BigDecimal#truncate sets n digits left of the decimal point to 0, if given n < 0" # ArgumentError: [BigDecimal#fix] wrong number of arguments (given 1, expected 0) |
|
@hmdne, I have fixed the for example In Ruby:
But in BigNumber this will raise the following error (as mentioned here):
can we skip the cc: @ronaldtse |
|
@suleman-uzair We need as much as is required for you to proceed with the work on Plurimath, anything more will likely help us in the future, but is not required. I will backport things upstream tomorrow. |
|
Thank you @hmdne, this works for me. @ronaldtse, this PR is finalized, let me know if I should merge this. |
|
@suleman-uzair We have merged your patch to upstream Opal. In the future we can rebase. |
This PR adds the support
powerandfixmethods for consistency with BigDecimal-Ruby.related to => plurimath/plurimath-js#28