Forum Discussion

Altera_Forum's avatar
Altera_Forum
Icon for Honored Contributor rankHonored Contributor
14 years ago

Special function calculation

sir, I'm using Verilog to program and Modelsim to simulate but i don't know how to use special function to calculate log, exponent, sin...Do i need add library ?

7 Replies

  • Altera_Forum's avatar
    Altera_Forum
    Icon for Honored Contributor rankHonored Contributor

    You didn't tell, if you need the mathematical functions only in the testbench or to be synthesizable?

  • Altera_Forum's avatar
    Altera_Forum
    Icon for Honored Contributor rankHonored Contributor

    --- Quote Start ---

    You didn't tell, if you need the mathematical functions only in the testbench or to be synthesizable?

    --- Quote End ---

    I need the mathematical functions in testbench only. Thank
  • Altera_Forum's avatar
    Altera_Forum
    Icon for Honored Contributor rankHonored Contributor

    You should review the real math functions provided by verilog

    --- Quote Start ---

    Table 17-18—Verilog to C real math function cross-listing

    Verilog function Equivalent C function Description

    $ln(x) log(x) Natural logarithm

    $log10(x) log10(x) Decimal logarithm

    $exp(x) exp(x) Exponential

    $sqrt(x) sqrt(x) Square root

    $pow(x,y) pow(x,y) x**y

    $floor(x) floor(x) Floor

    $ceil(x) ceil(x) Ceiling

    $sin(x) sin(x) Sine

    $cos(x) cos(x) Cosine

    $tan(x) tan(x) Tangent

    $asin(x) asin(x) Arc-sine

    $acos(x) acos(x) Arc-cosine

    $atan(x) atan(x) Arc-tangent

    $atan2(x,y) atan2(x,y) Arc-tangent of x/y

    $hypot(x,y) hypot(x,y) sqrt(x*x+y*y)

    $sinh(x) sinh(x) Hyperbolic sine

    $cosh(x) cosh(x) Hyperbolic cosine

    $tanh(x) tanh(x) Hyperbolic tangent

    $asinh(x) asinh(x) Arc-hyperbolic sine

    $acosh(x) acosh(x) Arc-hyperbolic cosine

    $atanh(x) atanh(x) Arc-hyperbolic tangent

    --- Quote End ---

  • Altera_Forum's avatar
    Altera_Forum
    Icon for Honored Contributor rankHonored Contributor

    Do I need to add any extra Verilog/VHDL codes (library or anything) in the simulation before I could call these special functions?