Is order saved when casting Double to Int64

Hi,

I want to save Integer, Double, TDate, TTime and Boolean values in the same column in a database.
Since the maximum size for all these is 8 bytes, I plan to use an Int64 column and cast all values
to Int64.

What I need to know is, if the order of different values is the same or if there are cases where it
will be different.

var
  d1: Double;
  d2: Double;
  i1 : Int64 absolute d1;
  i2 : Int64 absolute d2;
begin
  d1 := 2.33;
  i1:= d1;
  d2 := 4.112;
  i2 := d2;

  if d1 < d2
    then Assert(i1 < i2)

  if d1 > d2
    then Assert(i1 > i2)

cu Christian
0
Christian
7/16/2015 5:49:01 AM
embarcadero.delphi.general 4258 articles. 0 followers. Follow

3 Replies
622 Views

Similar Articles

[PageSpeed] 24

Christian wrote:

> I want to save Integer, Double, TDate, TTime and Boolean values in
> the same column in a database. Since the maximum size for all these
> is 8 bytes, I plan to use an Int64 column and cast all values to Int64.

And I presume you have another column that specifies what data type has been 
stored in your "special" column?  Otherwise how would you know how to interpret 
the value when reading it back?

> What I need to know is, if the order of different values is the same
> or if there are cases where it will be different.

What do you mean by "order" exactly?

> i1:= d1;

That is redundant.  Since d1 and i1 share the same memory, i1 automatically 
gains a value as soon as you assign a value to d1, and vice versa.

> i2 := d2;

Likewise.

> if d1 < d2
> then Assert(i1 < i2)
>
> if d1 > d2
> then Assert(i1 > i2)

I do not think that is a guarantee, since Int64 and Double have very different 
bit patterns to represent their respective values.  The only thing they have 
in common is that they both happen to use the same bit to represent the sign. 
 If the sign is 1, the value is negative, otherwise the value is positive. 
 If you need to compare two values against each other, you have to make sure 
they are in the same representation first.

-- 
Remy Lebeau (TeamB)
0
Remy
7/17/2015 5:25:48 PM
>> What I need to know is, if the order of different values is the same
>> or if there are cases where it will be different.

No. The meta information is in structure in the application itself.

>I do not think that is a guarantee, since Int64 and Double have very different 
>bit patterns to represent their respective values.  The only thing they have 

I ended up with the solution to have three columns

Double -> for Double, TDateTime
Integer -> for Integer, Boolean, References
String -> for Strings

The overhead of 8 bytes is not a problem today compared to avoid such complicate structures and it
is easier to search for a value.

cu Christian
0
Christian
7/17/2015 7:15:13 PM

    
0
Remy
7/17/2015 11:37:59 PM
Reply:

Similar Artilces:

Delphi 2007 to Delphi XE2 paint order change
Hello all, I have a program here that does some very specific work in the paint handlers and requires that the controls are painted from bottom to top. This worked just fine under Delphi 2007 but now that we have migrated to Delphi XE2, it no longer works. Tracing the paint order, we discovered that there are cases when the bottom most component (the form for instance) is drawn last instead of first, which means that the painting code we do in the program gets a black area for the bottom most control instead of its background. This was observed with D2007 and DXE2 on the same c...

What generals generally do
Reading a McChrystal thread elsewhere, I came across someone quoting a US general http://en.wikipedia.org/wiki/Smedley_Butler > I spent 33 years and four months in active military service and > during that period I spent most of my time as a high class thug for > Big Business, for Wall Street and the bankers. In short, I was a > racketeer, a gangster for capitalism. I helped make Mexico and > especially Tampico safe for American oil interests in 1914. I helped > make Haiti and Cuba a decent place for the National City Bank boys to > collect revenues in. I ...

delphi.general
Sorry if this is "out of topic"! but since some days ago I can't read the group *embarcadero.public.delphi.language.delphi.general* Does anybody know if there's something wrong with it? Or maybe is my reader? (Thunderbird) I get this messagge when I try to read the latest messages: Error! newsgroup server responded:no such article found Perhaps the article has expired <692702@forums.embarcadero.com> (33145) Click here to remove all expired articles sergio wrote: > Sorry if this is "out of topic"! but since some days ago I can'...

ORDER BY on an ORDER BY
I have a huge SQL-statement that picks the top 10 recently added rows from a table, for simplicity something like this:SELECT TOP 10  someDate, username FROM table ORDER BY someDate DESCWhen I have this table with the 10 rows with latest someDate  I want to sort the table by username instead. I want to do something like this:SELECT *FROM  (SELECT TOP 10  someDate, username FROM table ORDER BY someDate DESC) As Expr1ORDER BY username DESCMicrosoft Access, which is the database I use, then prints the error message "Error in GROUP BY clause.Unable to parse query text.&q...

Save as..Does not Save as..
I have a project that I want to save as a different project name in a different folder. Selecting Save Project as.. does not do this. It saves a few files and continues to use files in the original folder. I am trying to keep each version of the program I write. Is there anyway to do this without having to do a total redesign or editing hex files looking for the paths that need changing. Ray. Ray Firstly I have very few hard coded path references in my dpr. Most (but not all) files in the project live in the same directory. What I do is simply copy the files in the directo...

save or save as
since last update 2.24 (I think) I can't save as a page Horodatage : 08/03/2014 16:55:54 Erreur : FileUtils.File is not a constructor Fichier Source : chrome://global/content/contentAreaUtils.js Ligne : 571 -- cyberzen cyberzen wrote: > since last update 2.24 (I think) I can't save as a page > > Horodatage : 08/03/2014 16:55:54 > Erreur : FileUtils.File is not a constructor > Fichier Source : chrome://global/content/contentAreaUtils.js > Ligne : 571 No problem here saving this site <http://www.css3.info/> using File > Save Page As..., ...

superreview requested: [Bug 309027] Saving image does not open the save location window sometimes : [Attachment 199799] Avoid double command updates and potential for disagreeing variables by using o
Aaron Leventhal <aaronleventhal@moonset.net> has asked Brian Ryner <bryner@brianryner.com> for superreview: Bug 309027: Saving image does not open the save location window sometimes https://bugzilla.mozilla.org/show_bug.cgi?id=309027 Attachment 199799: Avoid double command updates and potential for disagreeing variables by using only one https://bugzilla.mozilla.org/attachment.cgi?id=199799&action=edit ------- Additional Comments from Aaron Leventhal <aaronleventhal@moonset.net> Brian, this is an impovement over what you already sr='d ...

superreview cancelled: [Bug 309027] Saving image does not open the save location window sometimes : [Attachment 199799] Avoid double command updates and potential for disagreeing variables by using o
Asa Dotzler <asa@mozilla.org> has cancelled Aaron Leventhal <aaronleventhal@moonset.net>'s request for superreview: Bug 309027: Saving image does not open the save location window sometimes https://bugzilla.mozilla.org/show_bug.cgi?id=309027 Attachment 199799: Avoid double command updates and potential for disagreeing variables by using only one https://bugzilla.mozilla.org/attachment.cgi?id=199799&action=edit ...

how do you save column order
What is the best way to remember the preferred order per user and arraign them in the preferred order after retrieving? Some columns are Computed Object columns, all have Tab = 0, using PB 6.5 If it is a grid dw, make all columns initially hidden. Then, make columns visible one by one starting with the 1st column. You can store the order info in the user INI file. This way you can save not only the order, but also columns that the user might want to hide. I did this a long while back and actually made use of the database rather than INI file to make it quicker but either way w...

Delphi XE ordering?
http://www.provantage.com/embarcadero-technologies-hdex00muenwb0~7BORM75L.htm is this allowed (to order) for a customer in EU? Rgds, Frenk > {quote:title=Frenk R wrote:}{quote} > http://www.provantage.com/embarcadero-technologies-hdex00muenwb0~7BORM75L.htm > > is this allowed (to order) for a customer in EU? > Rgds, > Frenk You have to purchase the product from the country where you will be using it the most. Provantage is a US reseller partner so you should purchase from a local partner instead. Thanks, Tim -- Tim Del Chiaro Product Marketing - RAD...

delphi.general Timer
This message is in MIME format. Since your mail reader does not understand this format, some or all of this message may not be legible. --JivePart=_202d5.zeB8CwDOH5aMJzMl Content-Type: text/plain; charset="Utf-8" For Paolo Valle --JivePart=_202d5.zeB8CwDOH5aMJzMl Content-Type: application/octet-stream; name="SubroutineTimer.pas" Content-Transfer-Encoding: base64 Content-Disposition: attachment; filename="SubroutineTimer.pas" dW5pdCBTdWJyb3V0aW5lVGltZXI7DQoNCmludGVyZmFjZQ0KDQpwcm9jZWR1cmUgU3RhcnRTdWJy b3V0aW5lVGltZXI7DQpmdW5jdGlvbiBHZXRTdWJSb...

General settings not being saved
I have sum totals columns in a trailer group that are set to a certain brush color and brush hatch. I save my settings and run my report and it all looks good. If I close out of my report and go back in, those two settings revert back to the default. Thinking I didn't actually save the settings, I changed them all back to how I wanted them, made sure I saved this time and ran my report, it all looked ok again. This time I clicked within my report and my settings reverted back to the default. I am running IM version 8 build 9506. Is this a bug in this build? Is there a file...

Int64[] integers = new Int64[Int64.MaxValue];
Hi to all, Int64[] integers = new Int64[Int64.MaxValue]; i write this in my application but this will raise an error as Arithmetic operation resulted in an overflow. So i change the code like this Int64[] integers = new Int64[Int32.MaxValue]; Exception of type 'System.OutOfMemoryException' was thrown. Experts please tell me why this happens? why cant i use max value of int64/32 array.  If this post is answer of your question then don't forgot to Click Mark As Answer  If you decalre the size of array to be Int64 which is 9223372036854775807so your system ran o...

Saving saved messages
I am going to do a reformat. How can I save my filters and saved messages? Terry wrote: > I am going to do a reformat. > > How can I save my filters and saved messages? > You could try Mozbackup: http://mozbackup.jasnapaka.com/ -- I wasn't born stupid; I've had to work hard at it all my life. David Craft ...

Web resources about - Is order saved when casting Double to Int64 - embarcadero.delphi.general

Casting on (knitting) - Wikipedia, the free encyclopedia
In knitting , casting on is a family of techniques for adding new stitches that do not depend on earlier stitches, i.e., stitches having an independent ...

THE HOBBIT Casting Update
Yikes! I can finally get back to some postings! We've finished our first block of shooting and moved straight into location scouting. More on ...

bubblegum casting (@bgumcasting) on Twitter
Sign in Sign up To bring you Twitter, we and our partners use cookies on our and other websites. Cookies help personalize Twitter content, tailor ...

Casting - Quora
Quora is your best source for knowledge.

3d-printer chocolate casting - Flickr - Photo Sharing!
i scanned myself with: www.123dapp.com/catch cleaned and fixed the mesh with: www.netfabb.com/basic.php then subtracted my face from a cube to ...

The Princess Bride - CASTING THE PRINCESS BRIDE - YouTube
Director Rob Reiner, screenwriter William Goldman, and various cast members, discuss the perfect casting in the iconic film The Princess Bride. ...

Australian republic: Bill Shorten reignites debate by casting doubt on relevance of the royals
Bill Shorten has used a debate in Parliament over the rules governing order of royal succession to re-commit Labor to the case for an Australian ...

Networking - Casting begins for Paul Hogan project
... Me Out of Here!, Julia Morris and Dr Chris Brown, with a touch of jungle fever. Photo: Supplied Who will play Hoges? Seven has confirmed casting ...

The most unexpected casting in 'Star Wars: The Force Awakens' is the voice of BB-8
The lovable new droid in “Star Wars: The Force Awakens,” BB-8, may speak in a mechanical garbled sound like the saga’s other famous short droid, ...

Xena reboot gets a writer, Lucy Lawless sadly not in casting talks
... better known as the director of the Evil Dead and first 3 Spiderman films), the original Xena, Lucy Lawless, has been missing from recent casting ...

Resources last updated: 1/2/2016 6:05:58 PM