• Skip to main content
  • Skip to search
  • Skip to footer
Cadence Home
  • This search text may be transcribed, used, stored, or accessed by our third-party service providers per our Cookie Policy and Privacy Policy.

  1. Community Forums
  2. Custom IC SKILL
  3. epxt() calculates wrong results - same with pow(), same...

Stats

  • Locked Locked
  • Replies 3
  • Subscribers 143
  • Views 1834
  • Members are here 0
This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

epxt() calculates wrong results - same with pow(), same with ** operator

Volker T
Volker T over 2 years ago

I ran a test script using the expt() function, and it gave odd results.

So I typed it directly into CIW command line:

expt(10 12)

=> -727379968

I would expect the answer to be 1000000000000.

It works for a power of 9, though:

expt(10 9)

=> 1000000000

Same happens with other exponents:

for(i -24 24 printf("%g\n" 1.0*expt(10 i)) )

=>

1e-24
1e-23
1e-22
1e-21
1e-20
1e-19
1e-18
1e-17
1e-16
1e-15
1e-14
1e-13
1e-12
1e-11
1e-10
1e-09
1e-08
1e-07
1e-06
1e-05
0.0001
0.001
0.01
0.1
1
10
100
1000
10000
100000
1e+06
1e+07
1e+08
1e+09
1.41007e+09
1.21575e+09
-7.2738e+08
1.31613e+09
2.76447e+08
-1.53049e+09
1.87492e+09
1.56933e+09
-1.48662e+09
-1.98128e+09
1.66199e+09
-5.5994e+08
-1.30443e+09
-1.59384e+08
-1.59384e+09

By the way: 10**12 is also -727379968 accoring to CIW...

Is there a bug?

  • Cancel
Parents
  • ebecheto
    ebecheto over 2 years ago

    expt(10.0 12.0);=> treats numbers as float. Otherwise they are treated as integer.

    Same behaviour with other programs.

    Also 1/3 ;=> 0

    Whereas 1/3.0 ;=> 0.333

    ++

    • Cancel
    • Vote Up +1 Vote Down
    • Cancel
Reply
  • ebecheto
    ebecheto over 2 years ago

    expt(10.0 12.0);=> treats numbers as float. Otherwise they are treated as integer.

    Same behaviour with other programs.

    Also 1/3 ;=> 0

    Whereas 1/3.0 ;=> 0.333

    ++

    • Cancel
    • Vote Up +1 Vote Down
    • Cancel
Children
  • Volker T
    Volker T over 2 years ago in reply to ebecheto

    Thank you very much!

    I thought I had also tested with expt(10 1.0*i) in my loop and got the same result, but apparently I forgot to save my code before testing again, so no wonder, the same unexpected results came out.

    I checked again, this time with expt(10 1.0*i) and a saved file and it works as expected.

    • Cancel
    • Vote Up 0 Vote Down
    • Cancel
  • Andrew Beckett
    Andrew Beckett over 2 years ago in reply to Volker T

    Rather than using 1.0*I you can also do float(i) to cast an integer to a float. Or if you just use expt(10.0 i) that would work too. Provided that one of the numbers is a float, it would be fine.

    Andrew

    • Cancel
    • Vote Up 0 Vote Down
    • Cancel

Community Guidelines

The Cadence Design Communities support Cadence users and technologists interacting to exchange ideas, news, technical information, and best practices to solve problems and get the most from Cadence technology. The community is open to everyone, and to provide the most value, we require participants to follow our Community Guidelines that facilitate a quality exchange of ideas and information. By accessing, contributing, using or downloading any materials from the site, you agree to be bound by the full Community Guidelines.

© 2025 Cadence Design Systems, Inc. All Rights Reserved.

  • Terms of Use
  • Privacy
  • Cookie Policy
  • US Trademarks
  • Do Not Sell or Share My Personal Information