Skip to content

Math.log not working correctly? #2930

Open
@codemonkeynorth

Description

@codemonkeynorth

Bug description

Mathf.log functions don't return the correct value

Steps to reproduce

export function test_log(x: f32): f32 {
  return Mathf.log(x) // x = 10 => -0.004908394999802113 // (incorrect)
}
export function test_log10(x: f32): f32 {
  return Mathf.log10(x) // x = 10 => 1.0 // (correct)
}
export function test_log2(x: f32): f32 {
  return Mathf.log2(x) // x = 10 => -0.005684611387550831 // (incorrect)
}

EXAMPLE FIX:

export function test_log_fixed(x: f32): f32 {
  // x= 10 => 2.3025851249694824 (correct)
  return Mathf.log10(x) * <f32>Math.LN10; 
}

export function test_log2_fixed(x: f32): f32 {
  // x = 10 => 3.321928024291992 (correct)
  return (Mathf.log10(x) * <f32>Math.LN10) / <f32>Math.LN2 
}

AssemblyScript version

0.28.2

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions