[gtkada] how to print a value with 16 bit precision (Nabh4u)
nabh4u
nabh4u at yahoo.co.in
Thu Jun 12 22:52:39 CEST 2008
Thanks a ton..! It works. Now i understand what you were trying to say.
Thanks a lot for all the explanation. I don't think i would have got that by
going through books or some online material. You saved me just on time.
Thanks,
Nabh4u.
Damien Carbonne wrote:
>
> nabh4u a écrit :
>> Thank you Damien for the information. Is this another procedure i need to
>> include in my program? can you tell me how can i add this part in my
>> code?
>> Thank you once again for the reply.
>>
>>
> You don't "include" (There is no "include" in Ada, but this is another
> story) a procedure but a package into which this procedure is defined.
> The package that contains this version of Put is already withed, it is
> Ada.Long_Float_Text_IO;
> In fact you are already using it, but with default values for last 3
> parameters.
> When you write:
> (1) Put (eps)
> the compiler understands this:
> (2) Put (eps, Default_Fore, Default_Aft, Default_Exp);
> Those default values are defined like this in Ada.Text_IO.Float_IO
> Default_Fore : Field := 2;
> Default_Aft : Field := Num'Digits - 1;
> Default_Exp : Field := 3;
>
> Ada.Text_IO.Float_IO is a generic package which is instantiated with
> Long_Float to give Ada.Long_Float_IO.
> So (1) is equivalent to:
> Put (eps, 2, 14, 3);
>
>
> Practically, you need to change:
> Put(cnt + eps + eps + eps + eps + eps + eps);
> into:
> Put(cnt + eps + eps + eps + eps + eps + eps, Aft => 16);
>
> Do the same thing for the other uses of Put with a Long_Float (You can
> find them yourself !)
>
> As indicated by Christoph Grein in his reply, this is indeed dubious as
> Float has 15 digits.
> But this is what you (your teacher?) asked.
>
> Regards
>
> Damien
>
>
>
>
>> Damien Carbonne wrote:
>>
>>> Hi,
>>>
>>> You are simply using default parameters of Put here:
>>> procedure Put
>>> (Item : Num;
>>> Fore : Field := Default_Fore;
>>> Aft : Field := Default_Aft;
>>> Exp : Field := Default_Exp);
>>>
>>> and Default_Aft is defined like that :
>>> Default_Aft : Field := Num'Digits - 1;
>>>
>>> As Long_Float has 15 digits, that explains the 14 printed ones.
>>>
>>> So you need to set Aft to the right value.
>>> It could be like that:
>>> Put (Foo) -> Put (Foo, Aft => 16);
>>>
>>> Damien
>>>
>>>
>>> nabh4u a écrit :
>>>
>>>> Hello everyone,
>>>>
>>>> Gurus i need help. I am new to Ada programming. It is very urgent,
>>>> please
>>>> help me. i have to submit this by tomorrow. I have a small project
>>>> where
>>>> i
>>>> compute the machine epsilon and i have to print the value with a 16 bit
>>>> precision. I have tried long_float and i am getting 14 bit precision
>>>> but
>>>> i
>>>> want a 16 bit precision. i have also tried to use type but was not
>>>> successful.
>>>>
>>>> my code is:
>>>>
>>>> with Ada.Text_IO,Ada.Integer_Text_IO,Ada.Long_Float_Text_IO;
>>>> use Ada.Text_IO,Ada.Integer_Text_IO,Ada.Long_Float_Text_IO;
>>>> Procedure Eps is
>>>> eps:Long_Float := 1.0;
>>>> epsp1:Long_Float;
>>>> pass:Integer := 0;
>>>> cnt:Long_Float := 1.0;
>>>> Begin
>>>> New_Line(1);
>>>> Put("*** Computing Machine Epsilon using Ada Language ***");
>>>> New_Line(2);
>>>> epsp1 := eps + 1.0;
>>>> Put(" Pass ");
>>>> Put(" ");
>>>> Put(" Machine Epsilon Value ");
>>>> New_Line(2);
>>>> while(epsp1 > cnt) loop
>>>> pass := pass + 1;
>>>> eps := 0.5 * eps;
>>>> epsp1 := eps + 1.0;
>>>> Put(pass);
>>>> Put(" ");
>>>> Put(eps);
>>>> New_Line;
>>>> end loop;
>>>> New_Line;
>>>> Put("Final Eps Value : ");
>>>> Put(eps);
>>>> New_Line;
>>>> Put("The Value of 1+eps+eps+eps+eps+eps+eps is : ");
>>>> Put(cnt + eps + eps + eps + eps + eps + eps);
>>>> New_Line;
>>>> Put("The Value of 1+(eps+eps+eps+eps+eps+eps) is : ");
>>>> Put(cnt + (eps + eps + eps + eps + eps + eps));
>>>> New_Line(2);
>>>> End Eps;
>>>>
>>>>
>>>>
>>> _______________________________________________
>>> gtkada mailing list
>>> gtkada at lists.adacore.com
>>> http://lists.adacore.com/mailman/listinfo/gtkada
>>>
>>>
>>>
>>
>>
>
> _______________________________________________
> gtkada mailing list
> gtkada at lists.adacore.com
> http://lists.adacore.com/mailman/listinfo/gtkada
>
>
--
View this message in context: http://www.nabble.com/how-to-print-a-value-with-16-bit-precision-tp17789846p17809458.html
Sent from the Gtk+ - Ada mailing list archive at Nabble.com.
More information about the gtkada
mailing list