<?xml version="1.0" encoding="UTF-8" standalone="yes" ?>
<!DOCTYPE bugzilla SYSTEM "https://bugs.webkit.org/page.cgi?id=bugzilla.dtd">

<bugzilla version="5.0.4.1"
          urlbase="https://bugs.webkit.org/"
          
          maintainer="admin@webkit.org"
>

    <bug>
          <bug_id>266942</bug_id>
          
          <creation_ts>2023-12-30 16:59:11 -0800</creation_ts>
          <short_desc>generateWasm.py: return value can be wrong due IEEE 754 precision</short_desc>
          <delta_ts>2024-01-02 12:27:18 -0800</delta_ts>
          <reporter_accessible>1</reporter_accessible>
          <cclist_accessible>1</cclist_accessible>
          <classification_id>1</classification_id>
          <classification>Unclassified</classification>
          <product>WebKit</product>
          <component>JavaScriptCore</component>
          <version>WebKit Local Build</version>
          <rep_platform>PC</rep_platform>
          <op_sys>Linux</op_sys>
          <bug_status>RESOLVED</bug_status>
          <resolution>FIXED</resolution>
          
          
          <bug_file_loc>https://github.com/WebKit/WebKit/pull/22270</bug_file_loc>
          <status_whiteboard></status_whiteboard>
          <keywords>InRadar</keywords>
          <priority>P2</priority>
          <bug_severity>Normal</bug_severity>
          <target_milestone>---</target_milestone>
          
          
          <everconfirmed>1</everconfirmed>
          <reporter name="Conrad Kostecki">conrad+webkitbugzilla</reporter>
          <assigned_to name="Nobody">webkit-unassigned</assigned_to>
          <cc>justin_michaud</cc>
    
    <cc>keith_miller</cc>
    
    <cc>mark.lam</cc>
    
    <cc>webkit-bug-importer</cc>
          

      

      

      

          <comment_sort_order>oldest_to_newest</comment_sort_order>  
          <long_desc isprivate="0" >
    <commentid>2002319</commentid>
    <comment_count>0</comment_count>
    <who name="Conrad Kostecki">conrad+webkitbugzilla</who>
    <bug_when>2023-12-30 16:59:11 -0800</bug_when>
    <thetext>The assert function currently checks, if power number raised to the number fits memorybits.

This seems not always work on every system, as it happens, that the float numbers are not correctly rounded.
I suspect, that this is related to the IEEE 754 precision. It looks like, that &apos;math.log&apos; always produced a float.

This patch adds an int, so its being rounded to a full number and works on my system, where otherwise the rounding would fail. The return method also returns the result as an int.

Example:
* start python (tested with 3.11 and 3.12)
$ import math

$ 2 ** 3
= 8

$ 2.0 ** 3.0
= 7.999999999999999

$ int(2.0) ** int(3.0)
= 8

$ 2 ** int(3.0)
= 8


diff --git a/Source/JavaScriptCore/wasm/generateWasm.py b/Source/JavaScriptCore/wasm/generateWasm.py
index 434223d346a0d..7a99210b60a21 100755
--- a/Source/JavaScriptCore/wasm/generateWasm.py
+++ b/Source/JavaScriptCore/wasm/generateWasm.py
@@ -136,5 +136,5 @@ def memoryLog2Alignment(op):
         if not match:
             print(op[&quot;name&quot;])
         memoryBits = int(match.group(2) if match.group(2) else match.group(1))
-    assert 2 ** math.log(memoryBits, 2) == memoryBits
+    assert 2 ** int(math.log(memoryBits, 2)) == memoryBits
     return str(int(math.log(memoryBits / 8, 2)))</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>2002590</commentid>
    <comment_count>1</comment_count>
    <who name="EWS">ews-feeder</who>
    <bug_when>2024-01-02 12:26:49 -0800</bug_when>
    <thetext>Committed 272577@main (509b303bf565): &lt;https://commits.webkit.org/272577@main&gt;

Reviewed commits have been landed. Closing PR #22270 and removing active labels.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>2002591</commentid>
    <comment_count>2</comment_count>
    <who name="Radar WebKit Bug Importer">webkit-bug-importer</who>
    <bug_when>2024-01-02 12:27:18 -0800</bug_when>
    <thetext>&lt;rdar://problem/120382432&gt;</thetext>
  </long_desc>
      
      

    </bug>

</bugzilla>