Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7668697
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T15:25:33+00:00 2026-05-31T15:25:33+00:00

I came across a surprising behaviour in that I cannot take the square power

  • 0

I came across a surprising behaviour in that I cannot take the square powerof a variable. Ada permits that the square power of the actual value be taken though. Below is my sample code:

with Ada.Text_IO; use Ada.Text_IO;
with Ada.Long_Float_Text_IO;
with Ada.Float_Text_IO;
with Ada.Numerics.Long_Elementary_Functions;
use  Ada.Numerics.Long_Elementary_Functions;


procedure Test_power is

  testing : constant := -0.11603;


begin

  Ada.Text_IO.Put("Works fine with numerical value entered directly: ");
  Ada.Long_Float_Text_IO.Put (Item => -0.11603 ** 2.0, Fore => 3, Aft  => 5, Exp  => 0);  
  Ada.Text_IO.New_Line;
  Ada.Text_IO.New_Line;
  Ada.Text_IO.Put("This does not work: ");
  Ada.Long_Float_Text_IO.Put (Item => testing ** 2.0, Fore => 3, Aft  => 5, Exp  => 0);  

end Test_power;

The outputon the screen is:

Works fine with numerical value entered directly:  -0.01346

This does not work:


Execution terminated by unhandled exception
Exception name: ADA.NUMERICS.ARGUMENT_ERROR
Message: a-ngelfu.adb:96 instantiated at a-nlelfu.ads:18
Call stack traceback locations:
0x413ed5 0x42771d 0x427a2a 0x4010b4 0x401146 0x7c817075

The compilation was done using:

GPS 4.4.1 (20091215) hosted on i686-pc-mingw32
GNAT GPL 2010 (20100603)

Two questions:

(a) What am I doing wrong when I take testing ** 2.0 ?

(b) The square of -0.11603 is positive 0.01346. So why I am also getting the negative sign in my first ouput?

After some additional testing:

If I take only positive 0.11603, then output (its square) gives

(a) -0.01346
(b) 0.01346

which can imply that part of the problem is with the negative sign.

Thanks a lot…

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-31T15:25:34+00:00Added an answer on May 31, 2026 at 3:25 pm

    The "**" operator raises Numerics.Operator_Error when the left operand is negative, or when both operands have the value zero.

    It’s not unreasonable to expect it to work when the right operand is mathematically an exact integer like 2.0, but for non-integer exponents the mathematical result is a complex number, and Ada.Numerics.Generic_Elementary_Functions doesn’t treat real numbers that happen to be exact integers as a special case.

    If all you want to do is square a number, use the built-in "**" operator with an integer exponent. In other words, change this:

    testing ** 2.0
    

    to this:

    testing ** 2
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Came across a line in OpenSSL that made me do a double take... if
I recently came across some surprising behaviour in Python generators: class YieldOne: def __iter__(self):
I came across a printed article by Bertrand Meyer where he states that tests
I came across a controller in an older set of code (Rails 1.2.3) that
I came across this post on the MSMobiles.com blog that says the following, among
I came across the web (don't recall where) a note that says that MS
Came across the following weird behaviour in ruby 1.8.6, in 1.8.7 it seems to
I came across this thread Node.js HTTPS Secure Error which mentions that the tls
Working with the fine mocking-framework MoQ, I came across a somewhat surprising facet (and
I came across an odd bug in my code that revealed an interesting behavior

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.