float

How to create a random float in Objective-C?

Hi, I'm trying to create a random float between 0.15 and 0.3 in Objective-C. The following code always returns 1: int randn = (random() % 15)+15; float pscale = (float)randn / 100; What am I doing wrong? ...

Is the binary representation of native types guaranteed the same on all targets?

I"m planning to store my data in a binary format as a resource, read it into an int buffer and basically pass it straight down to a native C++ function, which might cast it to a struct/class and work with it. No pointers, obviously, just ints and floats. The question is - what kind of fixing up do I need to do? I suppose that I need to ...

Double vs. BigDecimal?

I have to calculate some floating point variables and my colleague suggest me to use BigDecimal instead of double since it will be more precise. But I want to know what it is and how to make most out of BigDecimal? Thanks! ...

union consisting of float : completely insane output

#include <stdio.h> union NumericType { float value; int intvalue; }Values; int main() { Values.value = 1094795585.00; printf("%f \n",Values.value); return 0; } This program outputs as : 1094795648.000000 Can anybody explain Why is this happening? Why did the value of the float Values.value increase? Or am I m...

Assign zero to float in C

I've got in the habit of using float f = 0.; //with a trailing period when assigning a zero value to a float in C. Should I be using float f = 0.f; //with an explicit float size or just stop messing about and use float f = 0; //with no trailing anything? Where did I pick up that habit and why? Is any version more right or wrong than a...

IE7 float (not div's)

Hi there. I wanted to make simple form, without awesome div's and CSS - it structure is like: <form id="cform" action="/" method="post"> <fieldset> <label class="first" for="name">Nazwa firmy: </label><input id="name" name="name" type="text" /> <label class="first" for="email">Email: </label><input id="email" name="email" type="text" />...

Differences between 0x01 and 0x01f

I'm looking at the original source code for Identicons. There's a bit of code that does some bit twiddling to extract red, green and blue components: int blue = (code >> 16) & 0x01f; int green = (code >> 21) & 0x01f; int red = (code >> 27) & 0x01f; The code variable is a 32 bit integer. My question is this: What's the difference be...

css: float image to the left - problem

i'm trying to do something like: -------------------------------------------- | --------- text text text text text text | | | image | text text text text text text | | | | text text text text text text | | | | text text text text text text | | --------- text text text text text text | | text text text text text text tex...

setting the float value from Javascript

Hi I'm having trouble setting something to float right in JS. My code is as follows: var closebutton = document.createElement('div'); closebutton.style.styleFloat = "right"; alert(closebutton.style.styleFloat); closebutton.style.background = "#f00"; closebutton.innerHTML = '<a href="">&#10006;</a>'; titlebar.appendChild(closebutton); ...

Gotchas of JavaScript's Number type (C's double)

What are some important considerations for developers using JavaScript's Number type? I know it's an implementation of C's double type, but I'm a self-taught Python developer so that doesn't take me very far. Pointers to well-written articles will be great answers. Thanks! ...

CSS - auto width floated element (expandable float).

Hi, I have two floated collumns side by side. The user can hide/collapse one of that collumns. In that case I want the other collumn to expand to fit the entire container. Is this possible with CSS? In resume, it's possible to make a float to expand to the size of it's container? Even if the element is floated, if it has width:auto i...

Handling Massive (high precision) Floats in Ruby

I'm making an application which is listening to prices being updated regularly, but occasionally my data source throws me something like "1.79769313486232e+308". The numbers that get sent will never by really big numbers (eg. "179769313486232e+308"), but as with the example above, they come with a lot of precision. I'd be happy to drop ...

Trying to write a code for finding the machine epsilon

I am trying to find out the precision level for various floating point formats in C (i.e. float, double and long double). Here is the code I'm using at the moment: #include <stdio.h> #define N 100000 int main(void) { float max = 1.0, min = 0.0, test; int i; /* Counter for the conditional loop */ ...

Clearing last floated element in each row

I have a set of divs with variable heights that have been floated left. When there are too many of said divs on a single line, the next div wraps to a new row (as it should). The problem I'm having is that the new row is started at an offset x position on the new row, such that the div is beneath the last div in the previous row that has...

float value changes when passed to a method in objective-c

Ok here goes my situation: I have a core-data generated class Quantity which has one of its attributes 'Value', marked as a float. There's a convenience method in the Quantity class which helps me set this property: - (void)setValueValue:(float)value_ { [self setValue:[NSNumber numberWithFloat:value_]]; } Now when I set try se...

Rounding a float to 1/4ths in Objective C

what's the most elegant way of rounding a float to it's closest 1/4ths in Objective C? For example: 3.14 should be 3.25 2.72 should be 2.75 6.62 should be 6.50 1.99 should be 2.00 etc. ...

C: convert double to float, preserving decimal point precision

hi, i wanted to convert double to float in C, but wanted to preserve the decimal point exactly as possible without any changes... for example, let's say i have double d = 0.1108; double dd = 639728.170000; double ddd = 345.2345678 now correct me if i am wrong, i know that floating point precision is about 5 numbers after the...

Making a <dl> clear before ever <dd> in IE 7?

I'm trying make a <dl> to define the icons I am using on the page. I want it so that every icon is inside a <dt> and it's definition is inside the following <dl>. After every icon definition, I want a line break. Simple, right? Well, IE7 says no! Here is my HTML: <dl style="display: block;" id="surveysIcons" class="icons"> ...

What's the standard behavior of float:right following float:left?

Suppose there is such HTML tags: ​<span> <span id='s1'>Text 1</span> <span id='s2'>Text 2</span> </span>​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​ And the css style is: ​#s1 { float: left; } #s2 { float: right; } What is the standard behavior of the display? In some browser, I see Text 1 Text 2 In som...

Pitfalls of number values in Python, "How deep?"

I'm a fairly green programmer, and I'm learning Python right now. I'm up to chapter 17 in "Learn to Think Like a Computer Scientist" (Classes and Methods), and I just wrote my first doctest that failed in a way I truly do not fully understand: class Point(object): ''' represents a point object. attributes: x, y ''' ...