Questions tagged [cgfloat]

A CGFloat is the basic CoreGraphics type for all floating-point values in the Cocoa and Cocoa Touch UI frameworks.

A CGFloat is the basic CoreGraphics type for all floating-point values in the Cocoa and Cocoa Touch UI frameworks.

CGFloat is defined in the CGGeometry Reference of CoreGraphics, which defines structures for geometric primitives and functions that operate on them. Depending on your platform, a CGFloat is either 32 or 64 bits.

Use this tag when asking questions on CGFloat value types themselves, or CoreGraphics functions which use them.

207 questions
3
votes
2 answers

How come CGFloat is making up significant digits?

Possible Duplicate: CGFloat addition bug? I have a CGPoint (which is just a struct around two CGFloats). Can someone explain to me how these two lines of code: player.position = CGPointMake(player.position.x + 12.8f, player.position.y +…
InkGolem
  • 2,662
  • 1
  • 15
  • 22
3
votes
2 answers

how to make CGFloat value shorter when display in NSString?

I am new to objective-c. I want to display shorter CGFloat value in NSString. I know in C its easy. But i don't know how to do that in Objective-c. For example, CGFloat value = 0.333333; NSLog(@"%f%%",value*100); It will display 33.3333%. But i…
chancyWu
  • 14,073
  • 11
  • 62
  • 81
3
votes
3 answers

Creating a property from a CGFloat array - iOS

Trying to create a property, so I can set CGfloat array values on an instance of a class. Having a hard time figuring out how to do it. The CGFloat needs to have "size" [2] variable and numeric components like below: CGFloat locations[2] = {1.0,…
OWolf
  • 5,012
  • 15
  • 58
  • 93
3
votes
2 answers

Subtracting from CGFloat

NSLog(@"original float value = %f", [anNSNumber floatValue]); float newFloat = [anNSNumber floatValue] - 1.0f; NSLog(@"newFloat = %f", newFloat); Gives me orginal float value = 215987480044765184.000000 newFloat…
daihovey
  • 3,485
  • 13
  • 66
  • 110
2
votes
1 answer

How can I operate on a size_t and end up with a CGFloat?

To determine the ratio at which to scale an image, I'm using the following code (borrowed from Trevor Harmon's UIImage+Resize): CGFloat horizontalRatio = 600 / CGImageGetWidth(imageRef); CGFloat verticalRatio = 600 /…
Elise van Looij
  • 4,162
  • 3
  • 29
  • 52
2
votes
1 answer

Why does Swift report CGFloat.pi.significand to be exactly pi/2?

Running Xcode 11.3 Why is the significant component of pi equal to pi/2? print(CGFloat.pi.significand == CGFloat.pi/2). // true I expected the significant to be equivalent to the mantissa.. Did I miss something?
eharo2
  • 2,553
  • 1
  • 29
  • 39
2
votes
1 answer

Using floorf vs floor

I have the following situation in my code: //maxiumumHeight and rowHeight are CGFloats CGFloat rows = floorf(maximumHeight / rowHeight); CGFloat height = (rows * rowHeight); It works just fine, but I notice that when I use floor, it works fine…
NSMoron
  • 141
  • 1
  • 10
2
votes
1 answer

Coding SpriteKit game and I am receiving "Instance member 'minX' cannot be used on type 'CGRect"

I am having trouble fixing this error message down by the CGRect.minX/Y and CGRect.MaxX/Y. "Instance member 'minX' cannot be used on type 'CGRect" is the error. What could I do to fix it? func spawnNewDisc(){ var randomImageNumber =…
2
votes
5 answers

Binary operator (*) cannot be applied to operands CGPoint and CGFloat

I am trying to add gravity and velocity to a player but can't fix this error. I've tried multiple different things but always get the same type of error. Could anyone tell what I am doing wrong and why its not possible to use multiply a CGPoint and…
Yes
  • 43
  • 4
2
votes
2 answers

implicit conversion shortens 64 bit to 32 bit

Can someone explain why this causes the error stated in the title? CGFloat dx = fabs(lastPoint.x - currentPoint.x); Thanks
user7865437
  • 812
  • 14
  • 28
2
votes
1 answer

Subtract 1 minute between two NSDate

in my app I have a UIProgressView that shows the time elapsed between two NSDate. Everything works properly, each minute that passes UIProgressView advances by 0.1 per minute. The difference between the two dates is calculated in this way with a…
kAiN
  • 2,559
  • 1
  • 26
  • 54
2
votes
1 answer

CGFloat Returning +Inf

I'm calculating the percentage of a number like so: CGFloat total = 9; CGFloat onePercent = total / 100; CGFloat otherNum = 2; CGFloat otherNumPercentage = otherNum / onePercent; The result should be 22.2 repeating. However, it returns +Inf, which…
Josh Kahane
  • 16,765
  • 45
  • 140
  • 253
2
votes
3 answers

IF comparison on CGFloat value - Xcode 7 gives error

I have the following code: @property (nonatomic, assign) CGFloat floatValue; -- if (floatValue) { //Do something } Since Xcode 7 - compiler error occurs : Implicit conversion turns floating-point number into integer: 'CGFloat' to…
Ronald Palmer
  • 111
  • 1
  • 7
2
votes
1 answer

Place the height of UITextView in CGFloat variable

I am resizing a UITextView based on its content. I would like to be able to then get the height of the textview and place it in a variable: var heightFloat: CGFloat override func viewDidLayoutSubviews() { super.viewDidLayoutSubviews() …
Daniel Bramhall
  • 1,451
  • 4
  • 18
  • 24
2
votes
5 answers

Swift: Check which value in NSArray is closest to another given value

Lets say I have an array var values:[CGFloat] = [-12.0, 450, 300] I need to find out which of these numbers is closest to a given value, say var givenValue:CGFloat = 64 Is there an efficient way to find out which object in the array is closest to…
George Poulos
  • 539
  • 1
  • 6
  • 17