Timeline for Round up a CGFloat in Swift
Current License: CC BY-SA 3.0
15 events
when toggle format | what | by | license | comment | |
---|---|---|---|---|---|
Sep 23, 2014 at 7:49 | history | edited | Matt Gibson | CC BY-SA 3.0 |
Update with latest info
|
Jun 12, 2014 at 13:38 | comment | added | Martin R | @holex: Whether CGFloat is float or double in the compiled binary is completely determined at compile time. In a 32-bit binary (which can run on 32-bit and 64-bit hardware), CGFloat is a float. In a 64-bit binary (which can only run on 64-bit hardware), CGFloat is a double. - A Universal binary contains both a 32-bit and a 64-bit binary, and picks the most appropriate for the hardware at runtime for execution. - So for this question (whether to call ceil() or ceilf()) it is only relevant if the code is compiled as 32-bit or 64-bit. | |
Jun 12, 2014 at 12:49 | comment | added | Matt Gibson | No, no, this is a perfectly good debate to be having. To get some more opinions, I've created a new question, specifically asking about my solution here. Come join in! :) | |
Jun 12, 2014 at 11:32 | comment | added | holex | @MattGibson, or in a nuthsell: in compiling-time you don't know what the runtime architechure will be; and in my view making such decisions in compiling-time which depends on the runtime achitechture/environment, not a good practice or advice, even it would be faster. sorry for off the thread. | |
Jun 12, 2014 at 11:28 | comment | added | holex |
@MattGibson, I'm only trying to understand what you are selling here because the white gap is when the runtime architecture is different from the compiler-time architecture. according to what you just said, the application would work improperly in runtime because the two architectures will be different. like the CGFloat is stored in e.g. a float in runtime but the binary code would expect something else, because you already forced it in compiling-time to work with e.g. double later in runtime (or vica-verse). please, correct me if I'm wrong.
|
|
Jun 12, 2014 at 11:16 | history | edited | hsz | CC BY-SA 3.0 |
deleted 28 characters in body
|
Jun 12, 2014 at 11:14 | comment | added | Matt Gibson |
If you compile for 64-bit architecture, CGFloat is a double, so ceil works fine. If you compile for 32-bit architecture, CGFloat is a float, so ceilf works fine. What's the problem you're seeing, exactly? (Would you like to open a new question about this? I'd like to see more discussion, but the comments here probably isn't the place.)
|
|
Jun 12, 2014 at 11:03 | comment | added | holex | @MattGibson, according to your warning about they are stored differently on dirrefent achitectures, I still don't see how this solution would work properly on an 64 bits architecture if you compiled the project for 32 bits architechture, or vica-verse. somehow the logic is broken here, because the two theories mutually exclude each other, or the problem is not such serious and that is just too much ado for nothing. | |
Jun 12, 2014 at 11:00 | comment | added | Matt Gibson | (Though personally, I'd happily have seen this question left open for a lot longer to attract people with more solutions. I wonder if I can ask it again, only in a way not to have it immediately marked as a duplicate...) | |
Jun 12, 2014 at 10:55 | comment | added | Matt Gibson | @holex Which is why it's fast. Also, the problem is a compile-time problem; it's because CGFloat is defined differently when compiling for different architectures. | |
Jun 12, 2014 at 10:50 | comment | added | holex | my concern is about this solution is simply that it is a compiler-time solution only, and not a runtime solution. | |
Jun 12, 2014 at 10:48 | comment | added | Matt Gibson | #if is used for conditional compilation. If you used a similar if statement, the offending code would still be compiled, and you'd still get the compile-time error, even though it wouldn't run at run time. This way whichever line of code that won't compile on the selected architecture is never actually sent for compilation. | |
Jun 12, 2014 at 10:46 | comment | added | Oskar Persson | Horrible, but best solution so far. By the way, what's the difference between #if and if? | |
Jun 12, 2014 at 10:45 | vote | accept | Oskar Persson | ||
Jun 12, 2014 at 10:43 | history | answered | Matt Gibson | CC BY-SA 3.0 |