comp.lang.ada
 help / color / mirror / Atom feed
* Converting 64 bit float to record containing a record of one 32 bit integer and one 32 unsigned.
@ 2017-12-01  6:38 Petter Fryklund
  2017-12-01  9:24 ` Petter Fryklund
  0 siblings, 1 reply; 6+ messages in thread
From: Petter Fryklund @ 2017-12-01  6:38 UTC (permalink / raw)


This would be very easy if one could get a hex image from Float_IO. I haven't got any 64 bit integers in this app, since it is in old ObjectAda. Does anybody have a suggestions?

Regards,
Petter


^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: Converting 64 bit float to record containing a record of one 32 bit integer and one 32 unsigned.
  2017-12-01  6:38 Converting 64 bit float to record containing a record of one 32 bit integer and one 32 unsigned Petter Fryklund
@ 2017-12-01  9:24 ` Petter Fryklund
  2017-12-01 11:33   ` Jeffrey R. Carter
  0 siblings, 1 reply; 6+ messages in thread
From: Petter Fryklund @ 2017-12-01  9:24 UTC (permalink / raw)


Please don't waste time!

This was actually fun to implement! I created my own float2hex. This was possible since I could work with the Integer part only (Float'Floor) looping (taking the remainder after division by 16 and filling a string(1..15) backwards). Might be a coding practice for learners.

Regards,
Petter

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: Converting 64 bit float to record containing a record of one 32 bit integer and one 32 unsigned.
  2017-12-01  9:24 ` Petter Fryklund
@ 2017-12-01 11:33   ` Jeffrey R. Carter
  2017-12-01 12:32     ` Petter Fryklund
  0 siblings, 1 reply; 6+ messages in thread
From: Jeffrey R. Carter @ 2017-12-01 11:33 UTC (permalink / raw)


On 12/01/2017 10:24 AM, Petter Fryklund wrote:
> Please don't waste time!
> 
> This was actually fun to implement! I created my own float2hex. This was possible since I could work with the Integer part only (Float'Floor) looping (taking the remainder after division by 16 and filling a string(1..15) backwards). Might be a coding practice for learners.

 From your 1st msg, I thought you were trying to extract the bit image of the 
float type into your record, which is trivial. However, it appears you're trying 
to do the equivalent of Integer (F) for a value that won't fit in your largest 
integer types.

Yes, producing an image (in any base) is an interesting exercise. Why limit 
yourself to hex, though? Why not create an Image function that takes an optional 
Base parameter and produces the image in any base that you know how to represent?

PragmARC.Unbounded_Integers, for example, produces images in any base in 2 ..36. 
In fact, you could accomplish the same thing by using an instance of 
Ada.Text_IO.Float_IO to produce an image of the floor of your value in base 10 
without an exponent, trim off the decimal point and everything after it, pass 
this to the Value function of Unbounded_Integers, and pass that to Image with 
Base => 16.

https://github.com/jrcarter/PragmARC

-- 
Jeff Carter
"I'm a kike, a yid, a heebie, a hook nose! I'm Kosher,
Mum! I'm a Red Sea pedestrian, and proud of it!"
Monty Python's Life of Brian
77


^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: Converting 64 bit float to record containing a record of one 32 bit integer and one 32 unsigned.
  2017-12-01 11:33   ` Jeffrey R. Carter
@ 2017-12-01 12:32     ` Petter Fryklund
  2017-12-01 16:39       ` Jeffrey R. Carter
  0 siblings, 1 reply; 6+ messages in thread
From: Petter Fryklund @ 2017-12-01 12:32 UTC (permalink / raw)


Den fredag 1 december 2017 kl. 12:33:04 UTC+1 skrev Jeffrey R. Carter:
> On 12/01/2017 10:24 AM, Petter Fryklund wrote:
> > Please don't waste time!
> > 
> > This was actually fun to implement! I created my own float2hex. This was possible since I could work with the Integer part only (Float'Floor) looping (taking the remainder after division by 16 and filling a string(1..15) backwards). Might be a coding practice for learners.
> 
>  From your 1st msg, I thought you were trying to extract the bit image of the 
> float type into your record, which is trivial. However, it appears you're trying 
> to do the equivalent of Integer (F) for a value that won't fit in your largest 
> integer types.
> 
> Yes, producing an image (in any base) is an interesting exercise. Why limit 
> yourself to hex, though? Why not create an Image function that takes an optional 
> Base parameter and produces the image in any base that you know how to represent?
> 
> PragmARC.Unbounded_Integers, for example, produces images in any base in 2 ..36. 
> In fact, you could accomplish the same thing by using an instance of 
> Ada.Text_IO.Float_IO to produce an image of the floor of your value in base 10 
> without an exponent, trim off the decimal point and everything after it, pass 
> this to the Value function of Unbounded_Integers, and pass that to Image with 
> Base => 16.
> 
> https://github.com/jrcarter/PragmARC
> 
> -- 
> Jeff Carter
> "I'm a kike, a yid, a heebie, a hook nose! I'm Kosher,
> Mum! I'm a Red Sea pedestrian, and proud of it!"
> Monty Python's Life of Brian
> 77

Well since not in academia, I must solve the problems at hand, not invent new ones ;-) This solves the problem of storing a 64 bit value received from outside in a float value containing seconds since Jan 1st 1970. Old ObjectAda doesn't have 64 bit integers. Going via a hex value made the last part, storing the Integer value in the most significant part and the Natural value in the least significantpart, easy.

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: Converting 64 bit float to record containing a record of one 32 bit integer and one 32 unsigned.
  2017-12-01 12:32     ` Petter Fryklund
@ 2017-12-01 16:39       ` Jeffrey R. Carter
  2017-12-05  7:55         ` Petter Fryklund
  0 siblings, 1 reply; 6+ messages in thread
From: Jeffrey R. Carter @ 2017-12-01 16:39 UTC (permalink / raw)


On 12/01/2017 01:32 PM, Petter Fryklund wrote:
> 
> Well since not in academia, I must solve the problems at hand, not invent new ones ;-) This solves the problem of storing a 64 bit value received from outside in a float value containing seconds since Jan 1st 1970. Old ObjectAda doesn't have 64 bit integers. Going via a hex value made the last part, storing the Integer value in the most significant part and the Natural value in the least significantpart, easy.

It's not inventing new problems, it's designing something you need in a general, 
reusable way. Reinventing yet again the algorithm to convert a numeric value to 
an image rather than making use of existing facilities to accomplish the same end.

If you can find the quotient and remainder of dividing by 16, couldn't you do 
the same thing with 2 ** 32? Wouldn't the resulting values be directly 
convertible to your integer types?

-- 
Jeff Carter
"We call your door-opening request a silly thing."
Monty Python & the Holy Grail
17


^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: Converting 64 bit float to record containing a record of one 32 bit integer and one 32 unsigned.
  2017-12-01 16:39       ` Jeffrey R. Carter
@ 2017-12-05  7:55         ` Petter Fryklund
  0 siblings, 0 replies; 6+ messages in thread
From: Petter Fryklund @ 2017-12-05  7:55 UTC (permalink / raw)


You are right, of course!


^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2017-12-05  7:55 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-12-01  6:38 Converting 64 bit float to record containing a record of one 32 bit integer and one 32 unsigned Petter Fryklund
2017-12-01  9:24 ` Petter Fryklund
2017-12-01 11:33   ` Jeffrey R. Carter
2017-12-01 12:32     ` Petter Fryklund
2017-12-01 16:39       ` Jeffrey R. Carter
2017-12-05  7:55         ` Petter Fryklund

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox