Flash remoting and floating point values - actionscript-3

in xxxx.mxml (from flex) i have called the remote remote method (of java) the method return type is float
in the xxxx.mxml's remote objects result handler i need get the float values as Numeric.....or String..i tried with string...i did Alert.show to see the value some times i get exact value for eg, 0.5 is the value returning from java methid but here it will show 0.50000454...so on..how get the exact value?

It is because of the way floating point numbers are stored; basically they can't be stored precisely. A quick search in SO would reveal a lot of threads about this. Also read "What Every Computer Scientist Should Know About Floating-Point Arithmetic"
Thus the problem of getting the exact value boils down to what you define exact to be. Try rounding it to a given number of floating points at java end, convert the rounded number to a string (I'm not sure if this conversion would preserve the precision) and send that string.

Related

Primefaces Signature component curve fitting to keep String value to less than 4000 characters

I need to persist the value of p:signature in Oracle. I'm using the String value (JSON lines) of the component but often users get too elaborate with their cursive signature and the string exceeds the 4000 character limit on the Oracle field. I implemented a validator to ensure 4k or less but users get frustrated when form kicks back and they have to retry.
Is there a way to minify the json representation of the line data generated but still have the signature still visually look the same? Like a curve fitting function. If I simply truncate the string to 4k, that just truncates the end of the signature.
It would be nice if the component had a way to set precision of the curve or max flag that would automatically keep the JSON representation to less a maximum number of characters.
You are trying to hammer a square peg in a round hole. A signature is as big as it is. Even if you compress it, it's never guaranteed to be less than 4k. You should use the correct column type for your data. In this case either a CLOB (or a BLOB).

How to define the [float] data type in mysql version (6.0.11-alpha-community)

When I insert a number as 1234567.1234567 it will translate it to 1234567.1250.
How do I make it to save the correct number?
When I insert a number as 1234567.1234567 it will translate it to 1234567.1250
FLOATs are saved in four bytes, allowing for about 232 different values.
1234567.1234567 is not one of them. Encodable values are all some limited integer times a power of 2.
The closest encodable value is 1234567.125 or 9876537*2-3.
Code could use DOUBLE yet a similar issue applies.
The closest is about 1234567.1234567000065..., may be close enough for OP's purpose.

AS3: Function that determines if parameter is int or Number

I want to write a function that accepts either an int or a Number as a parameter and does different things depending on what type it is. My first question is what to use in the signature, Object or Number? I was thinking Number because it covers both int and Number.
function myFunction(p:Number):void { //Should p be of type Object or Number?
if (p is int) trace("Parameter is int.");
else if (p is Number) trace("Parameter is Number.");
}
The problem is I want it to be classified as a Number if the parameter has a decimal point like 1.00. That will still come up as int. Does anyone have any ideas how to do that? I suppose I could convert p to a String and then check to see if it contains a decimal point, but I was hoping there was an easier way.
The main problem I see is with the following sentence:
The problem is I want it to be classified as a Number if the parameter has a decimal point like 1.00.
Let's say we have an int variable called x, and we set it to 1. Does it look like 1, 1.00, or 1x10^-1? The answer is always no. Even if somebody were to type this:
myFunction(1.00);
the number still wouldn't actually look like anything. It's just the number one. Its only representation basically is however it looks in the actual machine bit representation (either floating point-style or just 000...001).
All it is is a number - whether stored in a Number variable or an int variable. Trying to convert it to a String won't help, as the information isn't there to begin with. The closest you're going to be able to come to this is pretty much going to be to use a String as the parameter type and see if somebody calls myFunction("1") or myFunction("1.00").
Only do something like this if you really have to, due to the wide range of stuff that could actually be stored in a String. Otherwise your is keywords should be the best way to go. But whichever one you choose, do not use an Object or untyped parameter; go with either a String or (much more preferably) a Number.

Emulating IBM floating point multiplication/addition in VBA

I am attempting to emulate a (no longer existing) mainframe report generator in an Access 2003 or Access 2010 environment. The data it generates must match exactly with paper reports from the early 70s. Unfortunately, the earliest years data were run on hardware that used IBM floating point representation instead of IEEE. With the help of Google, I've found a library of VBA functions that will convert a float from decimal to the IEEE 754 32bit binary format. I had to modify the library to accept either 32bit or 64bit floats, so I have a modest working knowledge of floating point formats, however, I'm having trouble making the conversion from IEEE to IBM binary format, as well as trouble multiplying and adding either the IBM or the IEEE numbers.
I haven't turned up any other libraries for performing this conversion and arithmetic operations in VBA - is there an easier way to go about this, or an existing library that I'm not finding? Failing that, a clear and straightforward explanation of the relevant algorithms?
Thanks in advance.
To be honest you'd probably do better to start by looking at the Hercules emulator.
http://www.hercules-390.org/ Other than that in theory with VBA you can use the Decimal type to get good results (note you have to CDec to create these) it uses 12 bits with a variable power of ten scalar.
A quick google shows this post from the hercules group, which confirms Alberts point about needing to know the hardware:
---Snip--
In theory, but rather less so in practice. S/360 and S/370 had a
choice of Scientific or Commercial instruction sets. The former added
the FP instructions and registers to the base; the latter the decimal
instructions, including Edit and Edit & Mark. But larger 360 (iirc /65
and up) and 370 (/155 and up) models had the union of the two, called
the Universal instruction set, and at some point the S/370 dropped the
option.
---snip---
I have to say that having looked at the hercules source code you'll probably need to figure out exactly which floating point operation codes (in terms of precision single,long, extended) are being performed.
The problem is here's your confusing the issue of decimal type in access, and that of single and double type floating point values available in access.
If you use the currency data type in access, this is a scaled integer, and will not produce rounding (that is what most of us use for financial calculations and reports). You can also use decimal values in access, and again they don't round at all as they are packed decimals.
However, both the single and double values available inside of access are in fact the same format and conform to the IEEE floating point standard.
For an access single variable, this is a 32bit number, and the range is:
-3.402823E38
to
-1.401298E-45 for negative values
and
1.401298E-45
to
3.402823E38 for positive values
That looks to be the same to me as the IEEE 754 standard.
So, if you add up values in access as a single, you should get the rouding same results.
So, Intel based, and Access single and doubles I believe are the same as this IEEE standard.
The only real issue it and here is what is the format of the original data you're pulling into access, and what kinds of text or string or conversion process is occurring when that data is pulled in and stored?
Access can convert numbers. Try typing these values at the access command line prompt (debug window)
? hex(255)
Above will show FF
? csng(&hFF)
Above will show 255
Edit:
Ah, ok, I see now I have this reversed, my wrong here. The problem here is assuming you convert a number to the older IBM format (Excess 64?), you will THEN have to get your hands on their code that they used for adding those numbers. In fact, even back then, different IBM models depending on what you purchased actually produced different results (more money = more precision).
So, not only do you need conversion routines to convert to the internal representation, you THEN need the routines that add/subtract/multiply those numbers. So, just having conversion routines is not going to get you very far, since you also have to duplicate their exact routines that do math. Those types of routines are likely not all created equal in terms of how they round numbers etc.

ActionScript Parameter Filtering

I'm setting up a custom class that accepts some Number parameters, but i need to limit those parameters and would like to know the best way of doing so.
currently, i'm simply calling if statements, and throwing an error if the number is above or below what's accepted. for example, there is a parameter that accepts and angle, but only between 0 and 90. in the case i've typed it as a uint so now i only have to check to see if it's above 90. there's also a parameter Number typed parameter that only accepts values between the range of 0.0 and 1.0.
Is my method of using if statements and throwing erros the usual way of filtering parameters?
Yes. The only way to get around this is to use the type system, e.g. create an AcuteAngle class that can only contain a number between 0 and 90. However, for what you're doing, it's better to just have if statements.
Your only other option is to silently clip inputs to the desirable range (for example, angle = angle % 90;). The official AS libraries tend to use this approach more often than not, but they're not terribly consistent.